コード例 #1
0
ファイル: net.go プロジェクト: ZhuZhengyi/eris-db
func Status() (*ctypes.ResultStatus, error) {
	db := dbm.NewMemDB()
	if genesisState == nil {
		genesisState = sm.MakeGenesisState(db, genDoc)
	}
	genesisHash := genesisState.Hash()
	latestHeight := blockStore.Height()
	var (
		latestBlockMeta *types.BlockMeta
		latestBlockHash []byte
		latestBlockTime int64
	)
	if latestHeight != 0 {
		latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
		latestBlockHash = latestBlockMeta.Hash
		latestBlockTime = latestBlockMeta.Header.Time.UnixNano()
	}

	return &ctypes.ResultStatus{
		NodeInfo:          p2pSwitch.NodeInfo(),
		GenesisHash:       genesisHash,
		PubKey:            privValidator.PubKey,
		LatestBlockHash:   latestBlockHash,
		LatestBlockHeight: latestHeight,
		LatestBlockTime:   latestBlockTime}, nil
}
コード例 #2
0
ファイル: node.go プロジェクト: ZhuZhengyi/eris-db
// Call Start() after adding the listeners.
func (n *Node) Start() error {
	n.book.Start()
	genState := sm.MakeGenesisState(dbm.NewMemDB(), n.genDoc)
	n.sw.SetNodeInfo(makeNodeInfo(n.sw, n.privKey, genState.Hash()))
	n.sw.SetNodePrivKey(n.privKey)
	_, err := n.sw.Start()
	return err
}
コード例 #3
0
ファイル: node_test.go プロジェクト: ZhuZhengyi/eris-db
func TestCompatibleNodeInfo(t *testing.T) {
	sw := p2p.NewSwitch()
	priv1, priv2 := types.GenPrivValidator(), types.GenPrivValidator()
	genDoc1, _, _ := stypes.RandGenesisDoc(5, true, 100, 4, true, 1000)
	genState1 := sm.MakeGenesisState(dbm.NewMemDB(), genDoc1)
	genDoc2, _, _ := stypes.RandGenesisDoc(5, true, 100, 4, true, 1000)
	genState2 := sm.MakeGenesisState(dbm.NewMemDB(), genDoc2)

	// incompatible genesis states
	n1 := makeNodeInfo(sw, priv1.PrivKey, genState1.Hash())
	n2 := makeNodeInfo(sw, priv2.PrivKey, genState2.Hash())
	if err := n1.CompatibleWith(n2); err == nil {
		t.Fatalf("Expected nodes to be incompatible due to genesis state")
	}

	// incompatible chain ids
	copy(n2.Genesis, n1.Genesis)
	n2.ChainID = "incryptowetrust"
	if err := n1.CompatibleWith(n2); err == nil {
		t.Fatalf("Expected nodes to be incompatible due to chain ID")
	}

	// incompatible versions
	n2.ChainID = n1.ChainID
	v := n1.Version.Tendermint
	spl := strings.Split(v, ".")
	n, err := strconv.Atoi(spl[0])
	if err != nil {
		t.Fatalf(err.Error())
	}
	spl[0] = strconv.Itoa(n + 1)
	n2.Version.Tendermint = strings.Join(spl, ".")
	if err := n1.CompatibleWith(n2); err == nil {
		t.Fatalf("Expected nodes to be incompatible due to major version")
	}

	// compatible
	n2.Version.Tendermint = n1.Version.Tendermint
	if err := n1.CompatibleWith(n2); err != nil {
		t.Fatalf("Expected nodes to be compatible")
	}
}