diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-02-27 10:41:01 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | 0ac79d780ba63c574d648552f887c9411fdd76fe (patch) | |
tree | 0afb53c6bd8bd10f1beae428460c4481ee876dc1 /dex | |
parent | d2a491c0b69bb0777b124e9ba278c05129bb327e (diff) | |
download | dexon-0ac79d780ba63c574d648552f887c9411fdd76fe.tar.gz dexon-0ac79d780ba63c574d648552f887c9411fdd76fe.tar.zst dexon-0ac79d780ba63c574d648552f887c9411fdd76fe.zip |
core: sync to latest core (#214)
* vendor: sync to latest core
* fix for single chain
Diffstat (limited to 'dex')
-rw-r--r-- | dex/app.go | 75 | ||||
-rw-r--r-- | dex/app_test.go | 18 | ||||
-rw-r--r-- | dex/governance.go | 21 | ||||
-rw-r--r-- | dex/handler.go | 15 | ||||
-rw-r--r-- | dex/helper_test.go | 14 | ||||
-rw-r--r-- | dex/peer.go | 37 | ||||
-rw-r--r-- | dex/peer_test.go | 97 | ||||
-rw-r--r-- | dex/protocol.go | 4 | ||||
-rw-r--r-- | dex/protocol_test.go | 64 |
9 files changed, 104 insertions, 241 deletions
diff --git a/dex/app.go b/dex/app.go index ab4e80058..6ef20684f 100644 --- a/dex/app.go +++ b/dex/app.go @@ -29,7 +29,6 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core" - "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/types" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" @@ -178,8 +177,8 @@ func (d *DexconApp) PreparePayload(position coreTypes.Position) (payload []byte, func (d *DexconApp) preparePayload(ctx context.Context, position coreTypes.Position) ( payload []byte, err error) { - d.chainRLock(position.ChainID) - defer d.chainRUnlock(position.ChainID) + d.chainRLock(uint32(0)) + defer d.chainRUnlock(uint32(0)) select { // This case will hit if previous RLock took too much time. case <-ctx.Done(): @@ -187,25 +186,9 @@ func (d *DexconApp) preparePayload(ctx context.Context, position coreTypes.Posit default: } - if position.Round > 0 { - // If round chain number changed but new round is not delivered yet, payload must be nil. - previousNumChains := d.gov.Configuration(position.Round - 1).NumChains - currentNumChains := d.gov.Configuration(position.Round).NumChains - if previousNumChains != currentNumChains { - deliveredRound, err := rawdb.ReadLastRoundNumber(d.chainDB) - if err != nil { - panic(fmt.Errorf("read current round error: %v", err)) - } - - if deliveredRound < position.Round { - return nil, nil - } - } - } - if position.Height != 0 { // Check if chain block height is strictly increamental. - chainLastHeight, ok := d.blockchain.GetChainLastConfirmedHeight(position.ChainID) + chainLastHeight, ok := d.blockchain.GetChainLastConfirmedHeight(uint32(0)) if !ok || chainLastHeight != position.Height-1 { log.Debug("Previous confirmed block not exists", "current pos", position.String(), "prev height", chainLastHeight, "ok", ok) @@ -213,7 +196,7 @@ func (d *DexconApp) preparePayload(ctx context.Context, position coreTypes.Posit } } - root, exist := d.chainRoot.Load(position.ChainID) + root, exist := d.chainRoot.Load(uint32(0)) if !exist { return nil, nil } @@ -222,14 +205,14 @@ func (d *DexconApp) preparePayload(ctx context.Context, position coreTypes.Posit if err != nil { return nil, err } - log.Debug("Prepare payload", "chain", position.ChainID, "height", position.Height) + log.Debug("Prepare payload", "chain", uint32(0), "height", position.Height) txsMap, err := d.txPool.Pending() if err != nil { return } - chainID := new(big.Int).SetUint64(uint64(position.ChainID)) + chainID := new(big.Int).SetUint64(uint64(uint32(0))) chainNums := new(big.Int).SetUint64(uint64(d.gov.GetNumChains(position.Round))) blockGasLimit := new(big.Int).SetUint64(d.gov.DexconConfiguration(position.Round).BlockGasLimit) blockGasUsed := new(big.Int) @@ -248,13 +231,13 @@ addressMap: } balance := currentState.GetBalance(address) - cost, exist := d.blockchain.GetCostInConfirmedBlocks(position.ChainID, address) + cost, exist := d.blockchain.GetCostInConfirmedBlocks(uint32(0), address) if exist { balance = new(big.Int).Sub(balance, cost) } var expectNonce uint64 - lastConfirmedNonce, exist := d.blockchain.GetLastNonceInConfirmedBlocks(position.ChainID, address) + lastConfirmedNonce, exist := d.blockchain.GetLastNonceInConfirmedBlocks(uint32(0), address) if !exist { expectNonce = currentState.GetNonce(address) } else { @@ -354,13 +337,13 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta return coreTypes.VerifyInvalidBlock } - d.chainRLock(block.Position.ChainID) - defer d.chainRUnlock(block.Position.ChainID) + d.chainRLock(uint32(0)) + defer d.chainRUnlock(uint32(0)) if block.Position.Height != 0 { // Check if target block is the next height to be verified, we can only // verify the next block in a given chain. - chainLastHeight, ok := d.blockchain.GetChainLastConfirmedHeight(block.Position.ChainID) + chainLastHeight, ok := d.blockchain.GetChainLastConfirmedHeight(uint32(0)) if !ok || chainLastHeight != block.Position.Height-1 { log.Debug("Previous confirmed block not exists", "current pos", block.Position.String(), "prev height", chainLastHeight, "ok", ok) @@ -368,34 +351,14 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta } } - if block.Position.Round > 0 { - // If round chain number changed but new round is not delivered yet, payload must be nil. - previousNumChains := d.gov.Configuration(block.Position.Round - 1).NumChains - currentNumChains := d.gov.Configuration(block.Position.Round).NumChains - if previousNumChains != currentNumChains { - deliveredRound, err := rawdb.ReadLastRoundNumber(d.chainDB) - if err != nil { - panic(fmt.Errorf("read current round error: %v", err)) - } - - if deliveredRound < block.Position.Round { - if len(block.Payload) > 0 { - return coreTypes.VerifyInvalidBlock - } - - return coreTypes.VerifyOK - } - } - } - // Get latest state with current chain. - root, exist := d.chainRoot.Load(block.Position.ChainID) + root, exist := d.chainRoot.Load(uint32(0)) if !exist { return coreTypes.VerifyRetryLater } currentState, err := d.blockchain.StateAt(*root.(*common.Hash)) - log.Debug("Verify block", "chain", block.Position.ChainID, "height", block.Position.Height) + log.Debug("Verify block", "chain", uint32(0), "height", block.Position.Height) if err != nil { log.Debug("Invalid state root", "root", *root.(*common.Hash), "err", err) return coreTypes.VerifyInvalidBlock @@ -428,7 +391,7 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta } // Check if nonce is strictly increasing for every address. - chainID := big.NewInt(int64(block.Position.ChainID)) + chainID := big.NewInt(int64(uint32(0))) chainNums := big.NewInt(int64(d.gov.GetNumChains(block.Position.Round))) for address, firstNonce := range addressNonce { @@ -438,7 +401,7 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta } var expectNonce uint64 - lastConfirmedNonce, exist := d.blockchain.GetLastNonceInConfirmedBlocks(block.Position.ChainID, address) + lastConfirmedNonce, exist := d.blockchain.GetLastNonceInConfirmedBlocks(uint32(0), address) if exist { expectNonce = lastConfirmedNonce + 1 } else { @@ -454,7 +417,7 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta // Calculate balance in last state (including pending state). addressesBalance := map[common.Address]*big.Int{} for address := range addressNonce { - cost, exist := d.blockchain.GetCostInConfirmedBlocks(block.Position.ChainID, address) + cost, exist := d.blockchain.GetCostInConfirmedBlocks(uint32(0), address) if exist { addressesBalance[address] = new(big.Int).Sub(currentState.GetBalance(address), cost) } else { @@ -509,7 +472,7 @@ func (d *DexconApp) BlockDelivered( log.Debug("DexconApp block deliver", "height", result.Height, "hash", blockHash, "position", blockPosition.String()) defer log.Debug("DexconApp block delivered", "height", result.Height, "hash", blockHash, "position", blockPosition.String()) - chainID := blockPosition.ChainID + chainID := uint32(0) d.chainLock(chainID) defer d.chainUnlock(chainID) @@ -567,8 +530,8 @@ func (d *DexconApp) BlockDelivered( // BlockConfirmed is called when a block is confirmed and added to lattice. func (d *DexconApp) BlockConfirmed(block coreTypes.Block) { - d.chainLock(block.Position.ChainID) - defer d.chainUnlock(block.Position.ChainID) + d.chainLock(uint32(0)) + defer d.chainUnlock(uint32(0)) log.Debug("DexconApp block confirmed", "block", block.String()) if err := d.blockchain.AddConfirmedBlock(&block); err != nil { diff --git a/dex/app_test.go b/dex/app_test.go index 73d952f31..221c55e0d 100644 --- a/dex/app_test.go +++ b/dex/app_test.go @@ -52,7 +52,7 @@ func TestPreparePayload(t *testing.T) { chainNum := uint32(0) root := dex.blockchain.CurrentBlock().Root() dex.app.chainRoot.Store(chainNum, &root) - payload, err := dex.app.PreparePayload(coreTypes.Position{ChainID: chainNum}) + payload, err := dex.app.PreparePayload(coreTypes.Position{}) if err != nil { t.Fatalf("prepare payload error: %v", err) } @@ -152,7 +152,6 @@ func TestVerifyBlock(t *testing.T) { // Prepare normal block. block := &coreTypes.Block{} block.Hash = coreCommon.NewRandomHash() - block.Position.ChainID = uint32(chainID.Uint64()) block.Position.Height = 1 block.ProposerID = coreTypes.NodeID{coreCommon.Hash{1, 2, 3}} block.Payload, block.Witness, err = prepareDataWithoutTxPool(dex, key, 0, 100) @@ -169,7 +168,6 @@ func TestVerifyBlock(t *testing.T) { // Prepare invalid nonce tx. block = &coreTypes.Block{} block.Hash = coreCommon.NewRandomHash() - block.Position.ChainID = uint32(chainID.Uint64()) block.Position.Height = 1 block.ProposerID = coreTypes.NodeID{coreCommon.Hash{1, 2, 3}} block.Payload, block.Witness, err = prepareDataWithoutTxPool(dex, key, 1, 100) @@ -186,7 +184,6 @@ func TestVerifyBlock(t *testing.T) { // Prepare invalid block height. block = &coreTypes.Block{} block.Hash = coreCommon.NewRandomHash() - block.Position.ChainID = uint32(chainID.Uint64()) block.Position.Height = 2 block.ProposerID = coreTypes.NodeID{coreCommon.Hash{1, 2, 3}} block.Payload, block.Witness, err = prepareDataWithoutTxPool(dex, key, 0, 100) @@ -203,7 +200,6 @@ func TestVerifyBlock(t *testing.T) { // Prepare reach block limit. block = &coreTypes.Block{} block.Hash = coreCommon.NewRandomHash() - block.Position.ChainID = uint32(chainID.Uint64()) block.Position.Height = 1 block.ProposerID = coreTypes.NodeID{coreCommon.Hash{1, 2, 3}} block.Payload, block.Witness, err = prepareDataWithoutTxPool(dex, key, 0, 10000) @@ -220,7 +216,6 @@ func TestVerifyBlock(t *testing.T) { // Prepare insufficient funds. block = &coreTypes.Block{} block.Hash = coreCommon.NewRandomHash() - block.Position.ChainID = uint32(chainID.Uint64()) block.Position.Height = 1 block.ProposerID = coreTypes.NodeID{coreCommon.Hash{1, 2, 3}} _, block.Witness, err = prepareDataWithoutTxPool(dex, key, 0, 0) @@ -255,7 +250,6 @@ func TestVerifyBlock(t *testing.T) { // Prepare invalid intrinsic gas. block = &coreTypes.Block{} block.Hash = coreCommon.NewRandomHash() - block.Position.ChainID = uint32(chainID.Uint64()) block.Position.Height = 1 block.ProposerID = coreTypes.NodeID{coreCommon.Hash{1, 2, 3}} _, block.Witness, err = prepareDataWithoutTxPool(dex, key, 0, 0) @@ -290,7 +284,6 @@ func TestVerifyBlock(t *testing.T) { // Prepare invalid transactions with nonce. block = &coreTypes.Block{} block.Hash = coreCommon.NewRandomHash() - block.Position.ChainID = uint32(chainID.Uint64()) block.Position.Height = 1 block.ProposerID = coreTypes.NodeID{coreCommon.Hash{1, 2, 3}} _, block.Witness, err = prepareDataWithoutTxPool(dex, key, 0, 0) @@ -398,7 +391,6 @@ func TestBlockConfirmed(t *testing.T) { block.Witness = witness block.Payload = payload block.ProposerID = coreTypes.NodeID{coreCommon.Hash{1, 2, 3}} - block.Position.ChainID = uint32(chainID.Uint64()) dex.app.BlockConfirmed(*block) expectCounter++ @@ -573,7 +565,6 @@ func addTx(dex *Dexon, nonce int, signer types.Signer, key *ecdsa.PrivateKey) ( func prepareData(dex *Dexon, key *ecdsa.PrivateKey, startNonce, txNum int) ( payload []byte, witness coreTypes.Witness, cost big.Int, nonce uint64, err error) { signer := types.NewEIP155Signer(dex.chainConfig.ChainID) - chainID := big.NewInt(0) for n := startNonce; n < startNonce+txNum; n++ { var tx *types.Transaction @@ -586,7 +577,7 @@ func prepareData(dex *Dexon, key *ecdsa.PrivateKey, startNonce, txNum int) ( nonce = uint64(n) } - payload, err = dex.app.PreparePayload(coreTypes.Position{ChainID: uint32(chainID.Uint64())}) + payload, err = dex.app.PreparePayload(coreTypes.Position{}) if err != nil { return } @@ -624,7 +615,7 @@ func prepareConfirmedBlockWithTxAndData(dex *Dexon, key *ecdsa.PrivateKey, data witness coreTypes.Witness ) - payload, err = dex.app.PreparePayload(coreTypes.Position{Round: round, ChainID: uint32(0)}) + payload, err = dex.app.PreparePayload(coreTypes.Position{Round: round}) if err != nil { return } @@ -638,7 +629,6 @@ func prepareConfirmedBlockWithTxAndData(dex *Dexon, key *ecdsa.PrivateKey, data block.Hash = coreCommon.NewRandomHash() block.Witness = witness block.Payload = payload - block.Position.ChainID = uint32(0) block.Position.Round = round block.ProposerID = coreTypes.NodeID{coreCommon.Hash{1, 2, 3}} @@ -692,7 +682,6 @@ func prepareConfirmedBlocks(dex *Dexon, keys []*ecdsa.PrivateKey, txNum int) (bl }, err error) { for _, key := range keys { address := crypto.PubkeyToAddress(key.PublicKey) - chainID := big.NewInt(0) // Prepare one block for pending. var ( @@ -712,7 +701,6 @@ func prepareConfirmedBlocks(dex *Dexon, keys []*ecdsa.PrivateKey, txNum int) (bl block.Hash = coreCommon.NewRandomHash() block.Witness = witness block.Payload = payload - block.Position.ChainID = uint32(chainID.Uint64()) block.ProposerID = coreTypes.NodeID{coreCommon.Hash{1, 2, 3}} status := dex.app.VerifyBlock(block) diff --git a/dex/governance.go b/dex/governance.go index 8b20cda19..56d08975e 100644 --- a/dex/governance.go +++ b/dex/governance.go @@ -229,12 +229,8 @@ func (d *DexconGovernance) ReportForkBlock(block1, block2 *coreTypes.Block) { } } -func (d *DexconGovernance) GetNumChains(round uint64) uint32 { - return 1 -} - -func (d *DexconGovernance) NotarySet(round uint64, chainID uint32) (map[string]struct{}, error) { - notarySet, err := d.nodeSetCache.GetNotarySet(round, chainID) +func (d *DexconGovernance) NotarySet(round uint64) (map[string]struct{}, error) { + notarySet, err := d.nodeSetCache.GetNotarySet(round) if err != nil { return nil, err } @@ -262,3 +258,16 @@ func (d *DexconGovernance) DKGSet(round uint64) (map[string]struct{}, error) { } return r, nil } + +func (d *DexconGovernance) ResetDKG(newSignedCRS []byte) { + data, err := vm.PackResetDKG(newSignedCRS) + if err != nil { + log.Error("failed to pack resetDKG input", "err", err) + return + } + + err = d.sendGovTx(context.Background(), data) + if err != nil { + log.Error("failed to send resetDKG tx", "err", err) + } +} diff --git a/dex/handler.go b/dex/handler.go index 474852913..4ffa01244 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -1005,9 +1005,8 @@ func (pm *ProtocolManager) BroadcastVote(vote *coreTypes.Vote) { pm.cache.addVote(vote) } label := peerLabel{ - set: notaryset, - chainID: vote.Position.ChainID, - round: vote.Position.Round, + set: notaryset, + round: vote.Position.Round, } for _, peer := range pm.peers.PeersWithLabel(label) { peer.AsyncSendVotes([]*coreTypes.Vote{vote}) @@ -1038,9 +1037,8 @@ func (pm *ProtocolManager) BroadcastRandomnessResult( pm.cache.addRandomness(randomness) // send to notary nodes first (direct) label := peerLabel{ - set: notaryset, - chainID: randomness.Position.ChainID, - round: randomness.Position.Round, + set: notaryset, + round: randomness.Position.Round, } randomnesses := []*coreTypes.BlockRandomnessResult{randomness} for _, peer := range pm.peers.PeersWithLabel(label) { @@ -1104,9 +1102,8 @@ func (pm *ProtocolManager) BroadcastPullBlocks( func (pm *ProtocolManager) BroadcastPullVotes( pos coreTypes.Position) { label := peerLabel{ - set: notaryset, - chainID: pos.ChainID, - round: pos.Round, + set: notaryset, + round: pos.Round, } for idx, peer := range pm.peers.PeersWithLabel(label) { if idx >= maxPullVotePeers { diff --git a/dex/helper_test.go b/dex/helper_test.go index e3d6aa3b7..3f901e6ec 100644 --- a/dex/helper_test.go +++ b/dex/helper_test.go @@ -130,10 +130,9 @@ func newTestProtocolManager(mode downloader.SyncMode, blocks int, generator func } tgov := &testGovernance{ - numChainsFunc: func(uint64) uint32 { return 3 }, lenCRSFunc: func() uint64 { return 1 }, dkgSetFunc: func(uint64) (map[string]struct{}, error) { return nil, nil }, - notarySetFunc: func(uint64, uint32) (map[string]struct{}, error) { return nil, nil }, + notarySetFunc: func(uint64) (map[string]struct{}, error) { return nil, nil }, } pm, err := NewProtocolManager(gspec.Config, mode, DefaultConfig.NetworkId, dMoment, evmux, &testTxPool{added: newtx}, engine, blockchain, db, true, tgov, &testApp{}) @@ -211,23 +210,18 @@ func newTestTransaction(from *ecdsa.PrivateKey, nonce uint64, datasize int) *typ // testGovernance is a fake, helper governance for testing purposes type testGovernance struct { - numChainsFunc func(uint64) uint32 lenCRSFunc func() uint64 - notarySetFunc func(uint64, uint32) (map[string]struct{}, error) + notarySetFunc func(uint64) (map[string]struct{}, error) dkgSetFunc func(uint64) (map[string]struct{}, error) } -func (g *testGovernance) GetNumChains(round uint64) uint32 { - return g.numChainsFunc(round) -} - func (g *testGovernance) LenCRS() uint64 { return g.lenCRSFunc() } func (g *testGovernance) NotarySet( - round uint64, chainID uint32) (map[string]struct{}, error) { - return g.notarySetFunc(round, chainID) + round uint64) (map[string]struct{}, error) { + return g.notarySetFunc(round) } func (g *testGovernance) DKGSet(round uint64) (map[string]struct{}, error) { diff --git a/dex/peer.go b/dex/peer.go index a157709f0..8ade9f152 100644 --- a/dex/peer.go +++ b/dex/peer.go @@ -119,9 +119,8 @@ const ( ) type peerLabel struct { - set setType - chainID uint32 - round uint64 + set setType + round uint64 } func (p peerLabel) String() string { @@ -130,7 +129,7 @@ func (p peerLabel) String() string { case dkgset: t = fmt.Sprintf("DKGSet round: %d", p.round) case notaryset: - t = fmt.Sprintf("NotarySet round: %d chain: %d", p.round, p.chainID) + t = fmt.Sprintf("NotarySet round: %d", p.round) } return t } @@ -962,24 +961,22 @@ func (ps *peerSet) BuildConnection(round uint64) { } } - for chainID := uint32(0); chainID < ps.gov.GetNumChains(round); chainID++ { - notaryLabel := peerLabel{set: notaryset, chainID: chainID, round: round} - if _, ok := ps.label2Nodes[notaryLabel]; !ok { - notaryPKs, err := ps.gov.NotarySet(round, chainID) - if err != nil { - log.Error("get notary set fail", - "round", round, "chainID", chainID, "err", err) - continue - } + notaryLabel := peerLabel{set: notaryset, round: round} + if _, ok := ps.label2Nodes[notaryLabel]; !ok { + notaryPKs, err := ps.gov.NotarySet(round) + if err != nil { + log.Error("get notary set fail", + "round", round, "err", err) + return + } - nodes := ps.pksToNodes(notaryPKs) - ps.label2Nodes[notaryLabel] = nodes + nodes := ps.pksToNodes(notaryPKs) + ps.label2Nodes[notaryLabel] = nodes - if _, exists := nodes[ps.srvr.Self().ID().String()]; exists { - ps.buildDirectConn(notaryLabel) - } else { - ps.buildGroupConn(notaryLabel) - } + if _, exists := nodes[ps.srvr.Self().ID().String()]; exists { + ps.buildDirectConn(notaryLabel) + } else { + ps.buildGroupConn(notaryLabel) } } } diff --git a/dex/peer_test.go b/dex/peer_test.go index 29b4971c5..76a28b1ef 100644 --- a/dex/peer_test.go +++ b/dex/peer_test.go @@ -19,41 +19,25 @@ func TestPeerSetBuildAndForgetConn(t *testing.T) { self := server.Self() table := newNodeTable() - gov := &testGovernance{ - numChainsFunc: func(uint64) uint32 { - return 3 - }, - } + gov := &testGovernance{} var nodes []*enode.Node for i := 0; i < 9; i++ { nodes = append(nodes, randomV4CompactNode()) } - round10 := [][]*enode.Node{ - {self, nodes[1], nodes[2]}, - {nodes[1], nodes[3]}, - {nodes[2], nodes[4]}, - } - round11 := [][]*enode.Node{ - {self, nodes[1], nodes[5]}, - {nodes[5], nodes[6]}, - {self, nodes[2], nodes[4]}, - } - round12 := [][]*enode.Node{ - {self, nodes[3], nodes[5]}, - {self, nodes[7], nodes[8]}, - {self, nodes[2], nodes[6]}, - } + round10 := []*enode.Node{self, nodes[1], nodes[2]} + round11 := []*enode.Node{self, nodes[1], nodes[5]} + round12 := []*enode.Node{self, nodes[3], nodes[5]} gov.notarySetFunc = func( - round uint64, cid uint32) (map[string]struct{}, error) { - m := map[uint64][][]*enode.Node{ + round uint64) (map[string]struct{}, error) { + m := map[uint64][]*enode.Node{ 10: round10, 11: round11, 12: round12, } - return newTestNodeSet(m[round][cid]), nil + return newTestNodeSet(m[round]), nil } gov.dkgSetFunc = func(round uint64) (map[string]struct{}, error) { @@ -73,58 +57,31 @@ func TestPeerSetBuildAndForgetConn(t *testing.T) { ps.BuildConnection(12) expectedlabel2Nodes := map[peerLabel]map[string]*enode.Node{ - {set: notaryset, round: 10, chainID: 0}: { + {set: notaryset, round: 10}: { self.ID().String(): self, nodes[1].ID().String(): nodes[1], nodes[2].ID().String(): nodes[2], }, - {set: notaryset, round: 10, chainID: 1}: { - nodes[1].ID().String(): nodes[1], - nodes[3].ID().String(): nodes[3], - }, - {set: notaryset, round: 10, chainID: 2}: { - nodes[2].ID().String(): nodes[2], - nodes[4].ID().String(): nodes[4], - }, {set: dkgset, round: 10}: { self.ID().String(): self, nodes[1].ID().String(): nodes[1], nodes[3].ID().String(): nodes[3], }, - {set: notaryset, round: 11, chainID: 0}: { + {set: notaryset, round: 11}: { self.ID().String(): self, nodes[1].ID().String(): nodes[1], nodes[5].ID().String(): nodes[5], }, - {set: notaryset, round: 11, chainID: 1}: { - nodes[5].ID().String(): nodes[5], - nodes[6].ID().String(): nodes[6], - }, - {set: notaryset, round: 11, chainID: 2}: { - self.ID().String(): self, - nodes[2].ID().String(): nodes[2], - nodes[4].ID().String(): nodes[4], - }, {set: dkgset, round: 11}: { nodes[1].ID().String(): nodes[1], nodes[2].ID().String(): nodes[2], nodes[5].ID().String(): nodes[5], }, - {set: notaryset, round: 12, chainID: 0}: { + {set: notaryset, round: 12}: { self.ID().String(): self, nodes[3].ID().String(): nodes[3], nodes[5].ID().String(): nodes[5], }, - {set: notaryset, round: 12, chainID: 1}: { - self.ID().String(): self, - nodes[7].ID().String(): nodes[7], - nodes[8].ID().String(): nodes[8], - }, - {set: notaryset, round: 12, chainID: 2}: { - self.ID().String(): self, - nodes[2].ID().String(): nodes[2], - nodes[6].ID().String(): nodes[6], - }, {set: dkgset, round: 12}: { self.ID().String(): self, nodes[3].ID().String(): nodes[3], @@ -137,14 +94,11 @@ func TestPeerSetBuildAndForgetConn(t *testing.T) { } expectedDirectConn := map[peerLabel]struct{}{ - {set: notaryset, round: 10, chainID: 0}: {}, - {set: notaryset, round: 11, chainID: 0}: {}, - {set: notaryset, round: 11, chainID: 2}: {}, - {set: notaryset, round: 12, chainID: 0}: {}, - {set: notaryset, round: 12, chainID: 1}: {}, - {set: notaryset, round: 12, chainID: 2}: {}, - {set: dkgset, round: 10}: {}, - {set: dkgset, round: 12}: {}, + {set: notaryset, round: 10}: {}, + {set: notaryset, round: 11}: {}, + {set: notaryset, round: 12}: {}, + {set: dkgset, round: 10}: {}, + {set: dkgset, round: 12}: {}, } if !reflect.DeepEqual(ps.directConn, expectedDirectConn) { @@ -152,9 +106,6 @@ func TestPeerSetBuildAndForgetConn(t *testing.T) { } expectedGroupConn := []peerLabel{ - {set: notaryset, round: 10, chainID: 1}, - {set: notaryset, round: 10, chainID: 2}, - {set: notaryset, round: 11, chainID: 1}, {set: dkgset, round: 11}, } @@ -196,21 +147,11 @@ func TestPeerSetBuildAndForgetConn(t *testing.T) { ps.ForgetConnection(11) expectedlabel2Nodes = map[peerLabel]map[string]*enode.Node{ - {set: notaryset, round: 12, chainID: 0}: { + {set: notaryset, round: 12}: { self.ID().String(): self, nodes[3].ID().String(): nodes[3], nodes[5].ID().String(): nodes[5], }, - {set: notaryset, round: 12, chainID: 1}: { - self.ID().String(): self, - nodes[7].ID().String(): nodes[7], - nodes[8].ID().String(): nodes[8], - }, - {set: notaryset, round: 12, chainID: 2}: { - self.ID().String(): self, - nodes[2].ID().String(): nodes[2], - nodes[6].ID().String(): nodes[6], - }, {set: dkgset, round: 12}: { self.ID().String(): self, nodes[3].ID().String(): nodes[3], @@ -223,10 +164,8 @@ func TestPeerSetBuildAndForgetConn(t *testing.T) { } expectedDirectConn = map[peerLabel]struct{}{ - {set: notaryset, round: 12, chainID: 0}: {}, - {set: notaryset, round: 12, chainID: 1}: {}, - {set: notaryset, round: 12, chainID: 2}: {}, - {set: dkgset, round: 12}: {}, + {set: notaryset, round: 12}: {}, + {set: dkgset, round: 12}: {}, } if !reflect.DeepEqual(ps.directConn, expectedDirectConn) { diff --git a/dex/protocol.go b/dex/protocol.go index 6ee02959a..0e3f50eba 100644 --- a/dex/protocol.go +++ b/dex/protocol.go @@ -152,11 +152,9 @@ type txPool interface { type governance interface { GetRoundHeight(uint64) uint64 - GetNumChains(uint64) uint32 - LenCRS() uint64 - NotarySet(uint64, uint32) (map[string]struct{}, error) + NotarySet(uint64) (map[string]struct{}, error) DKGSet(uint64) (map[string]struct{}, error) } diff --git a/dex/protocol_test.go b/dex/protocol_test.go index aa06d7293..fb414613e 100644 --- a/dex/protocol_test.go +++ b/dex/protocol_test.go @@ -327,15 +327,11 @@ func TestRecvLatticeBlocks(t *testing.T) { ParentHash: coreCommon.Hash{1, 1, 1, 1, 1}, Hash: coreCommon.Hash{2, 2, 2, 2, 2}, Position: coreTypes.Position{ - ChainID: 11, - Round: 12, - Height: 13, + Round: 12, + Height: 13, }, Timestamp: time.Now().UTC(), - Acks: coreCommon.NewSortedHashes(coreCommon.Hashes([]coreCommon.Hash{ - {101}, {100}, {102}, - })), - Payload: []byte{3, 3, 3, 3, 3}, + Payload: []byte{3, 3, 3, 3, 3}, Witness: coreTypes.Witness{ Height: 13, Data: []byte{4, 4, 4, 4, 4}, @@ -382,15 +378,11 @@ func TestSendLatticeBlocks(t *testing.T) { ParentHash: coreCommon.Hash{1, 1, 1, 1, 1}, Hash: coreCommon.Hash{2, 2, 2, 2, 2}, Position: coreTypes.Position{ - ChainID: 11, - Round: 12, - Height: 13, + Round: 12, + Height: 13, }, Timestamp: time.Now().UTC(), - Acks: coreCommon.NewSortedHashes(coreCommon.Hashes([]coreCommon.Hash{ - {101}, {100}, {102}, - })), - Payload: []byte{3, 3, 3, 3, 3}, + Payload: []byte{3, 3, 3, 3, 3}, Witness: coreTypes.Witness{ Height: 13, Data: []byte{4, 4, 4, 4, 4}, @@ -440,9 +432,8 @@ func TestRecvVotes(t *testing.T) { ProposerID: coreTypes.NodeID{coreCommon.Hash{1, 2, 3}}, Period: 10, Position: coreTypes.Position{ - ChainID: 11, - Round: 12, - Height: 13, + Round: 12, + Height: 13, }, }, Signature: coreCrypto.Signature{ @@ -477,9 +468,8 @@ func TestSendVotes(t *testing.T) { ProposerID: coreTypes.NodeID{coreCommon.Hash{1, 2, 3}}, Period: 10, Position: coreTypes.Position{ - ChainID: 1, - Round: 10, - Height: 13, + Round: 10, + Height: 13, }, }, Signature: coreCrypto.Signature{ @@ -528,11 +518,7 @@ func TestSendVotes(t *testing.T) { isReceiver bool }{ { - label: &peerLabel{set: notaryset, chainID: 1, round: 10}, - isReceiver: true, - }, - { - label: &peerLabel{set: notaryset, chainID: 1, round: 10}, + label: &peerLabel{set: notaryset, round: 10}, isReceiver: true, }, { @@ -540,15 +526,11 @@ func TestSendVotes(t *testing.T) { isReceiver: false, }, { - label: &peerLabel{set: notaryset, chainID: 1, round: 11}, + label: &peerLabel{set: notaryset, round: 11}, isReceiver: false, }, { - label: &peerLabel{set: notaryset, chainID: 2, round: 10}, - isReceiver: false, - }, - { - label: &peerLabel{set: dkgset, chainID: 1, round: 10}, + label: &peerLabel{set: dkgset, round: 10}, isReceiver: false, }, } @@ -678,9 +660,8 @@ func TestRecvAgreement(t *testing.T) { ProposerID: coreTypes.NodeID{coreCommon.Hash{1, 2, 3}}, Period: 10, Position: coreTypes.Position{ - ChainID: 1, - Round: 10, - Height: 13, + Round: 10, + Height: 13, }, }, Signature: coreCrypto.Signature{ @@ -723,9 +704,8 @@ func TestSendAgreement(t *testing.T) { ProposerID: coreTypes.NodeID{coreCommon.Hash{1, 2, 3}}, Period: 10, Position: coreTypes.Position{ - ChainID: 1, - Round: 10, - Height: 13, + Round: 10, + Height: 13, }, }, Signature: coreCrypto.Signature{ @@ -769,9 +749,8 @@ func TestRecvRandomnesses(t *testing.T) { randomness := coreTypes.BlockRandomnessResult{ BlockHash: coreCommon.Hash{8, 8, 8}, Position: coreTypes.Position{ - ChainID: 1, - Round: 10, - Height: 13, + Round: 10, + Height: 13, }, Randomness: []byte{7, 7, 7, 7}, } @@ -802,9 +781,8 @@ func TestSendRandomnesses(t *testing.T) { randomness := coreTypes.BlockRandomnessResult{ BlockHash: coreCommon.Hash{8, 8, 8}, Position: coreTypes.Position{ - ChainID: 1, - Round: 10, - Height: 13, + Round: 10, + Height: 13, }, Randomness: []byte{7, 7, 7, 7}, } |