diff options
-rw-r--r-- | core/configuration-chain.go | 5 | ||||
-rw-r--r-- | core/configuration-chain_test.go | 3 | ||||
-rw-r--r-- | core/consensus.go | 7 | ||||
-rw-r--r-- | core/lattice-data.go | 6 | ||||
-rw-r--r-- | core/lattice-data_test.go | 3 | ||||
-rw-r--r-- | core/utils/nodeset-cache.go (renamed from core/nodeset-cache.go) | 4 | ||||
-rw-r--r-- | core/utils/nodeset-cache_test.go (renamed from core/nodeset-cache_test.go) | 15 | ||||
-rw-r--r-- | integration_test/node.go | 3 |
8 files changed, 20 insertions, 26 deletions
diff --git a/core/configuration-chain.go b/core/configuration-chain.go index bda2fdf..03a4602 100644 --- a/core/configuration-chain.go +++ b/core/configuration-chain.go @@ -26,6 +26,7 @@ import ( "github.com/dexon-foundation/dexon-consensus/core/crypto" "github.com/dexon-foundation/dexon-consensus/core/types" typesDKG "github.com/dexon-foundation/dexon-consensus/core/types/dkg" + "github.com/dexon-foundation/dexon-consensus/core/utils" ) // Errors for configuration chain.. @@ -51,7 +52,7 @@ type configurationChain struct { tsig map[common.Hash]*tsigProtocol tsigTouched map[common.Hash]struct{} tsigReady *sync.Cond - cache *NodeSetCache + cache *utils.NodeSetCache dkgSet map[types.NodeID]struct{} mpkReady bool pendingPrvShare map[types.NodeID]*typesDKG.PrivateShare @@ -64,7 +65,7 @@ func newConfigurationChain( ID types.NodeID, recv dkgReceiver, gov Governance, - cache *NodeSetCache, + cache *utils.NodeSetCache, logger common.Logger) *configurationChain { return &configurationChain{ ID: ID, diff --git a/core/configuration-chain_test.go b/core/configuration-chain_test.go index b3d8ff4..129d07c 100644 --- a/core/configuration-chain_test.go +++ b/core/configuration-chain_test.go @@ -32,6 +32,7 @@ import ( "github.com/dexon-foundation/dexon-consensus/core/test" "github.com/dexon-foundation/dexon-consensus/core/types" typesDKG "github.com/dexon-foundation/dexon-consensus/core/types/dkg" + "github.com/dexon-foundation/dexon-consensus/core/utils" ) type ConfigurationChainTestSuite struct { @@ -174,7 +175,7 @@ func (s *ConfigurationChainTestSuite) runDKG( for _, nID := range s.nIDs { gov, err := test.NewGovernance(pks, 50*time.Millisecond, ConfigRoundShift) s.Require().NoError(err) - cache := NewNodeSetCache(gov) + cache := utils.NewNodeSetCache(gov) cfgChains[nID] = newConfigurationChain( nID, recv, gov, cache, &common.NullLogger{}) recv.nodes[nID] = cfgChains[nID] diff --git a/core/consensus.go b/core/consensus.go index 69131e6..99cb7c1 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -29,6 +29,7 @@ import ( "github.com/dexon-foundation/dexon-consensus/core/crypto" "github.com/dexon-foundation/dexon-consensus/core/types" typesDKG "github.com/dexon-foundation/dexon-consensus/core/types/dkg" + "github.com/dexon-foundation/dexon-consensus/core/utils" ) // Errors for consensus core. @@ -187,7 +188,7 @@ type consensusDKGReceiver struct { ID types.NodeID gov Governance authModule *Authenticator - nodeSetCache *NodeSetCache + nodeSetCache *utils.NodeSetCache cfgModule *configurationChain network Network logger common.Logger @@ -295,7 +296,7 @@ type Consensus struct { // Misc. dMoment time.Time - nodeSetCache *NodeSetCache + nodeSetCache *utils.NodeSetCache round uint64 roundToNotify uint64 lock sync.RWMutex @@ -319,7 +320,7 @@ func NewConsensus( var round uint64 logger.Debug("Calling Governance.Configuration", "round", round) config := gov.Configuration(round) - nodeSetCache := NewNodeSetCache(gov) + nodeSetCache := utils.NewNodeSetCache(gov) logger.Debug("Calling Governance.CRS", "round", round) // Setup auth module. authModule := NewAuthenticator(prv) diff --git a/core/lattice-data.go b/core/lattice-data.go index ce6d32b..6fe810a 100644 --- a/core/lattice-data.go +++ b/core/lattice-data.go @@ -26,12 +26,12 @@ import ( "github.com/dexon-foundation/dexon-consensus/common" "github.com/dexon-foundation/dexon-consensus/core/blockdb" "github.com/dexon-foundation/dexon-consensus/core/types" + "github.com/dexon-foundation/dexon-consensus/core/utils" ) // Errors for sanity check error. var ( ErrDuplicatedAckOnOneChain = fmt.Errorf("duplicated ack on one chain") - ErrInvalidChainID = fmt.Errorf("invalid chain id") ErrInvalidProposerID = fmt.Errorf("invalid proposer id") ErrInvalidWitness = fmt.Errorf("invalid witness data") ErrInvalidBlock = fmt.Errorf("invalid block") @@ -181,7 +181,7 @@ func (data *latticeData) sanityCheck(b *types.Block) error { } // Check if the chain id is valid. if b.Position.ChainID >= config.numChains { - return ErrInvalidChainID + return utils.ErrInvalidChainID } // Make sure parent block is arrived. chain := data.chains[b.Position.ChainID] @@ -382,7 +382,7 @@ func (data *latticeData) prepareBlock(b *types.Block) error { } // If chainID is illegal in this round, reject it. if b.Position.ChainID >= config.numChains { - return ErrInvalidChainID + return utils.ErrInvalidChainID } // Reset fields to make sure we got these information from parent block. b.Position.Height = 0 diff --git a/core/lattice-data_test.go b/core/lattice-data_test.go index e4a894f..24f45e6 100644 --- a/core/lattice-data_test.go +++ b/core/lattice-data_test.go @@ -27,6 +27,7 @@ import ( "github.com/dexon-foundation/dexon-consensus/core/blockdb" "github.com/dexon-foundation/dexon-consensus/core/test" "github.com/dexon-foundation/dexon-consensus/core/types" + "github.com/dexon-foundation/dexon-consensus/core/utils" "github.com/stretchr/testify/suite" ) @@ -217,7 +218,7 @@ func (s *LatticeDataTestSuite) TestSanityCheck() { Timestamp: time.Now().UTC(), }) // Invalid chain ID. - check(ErrInvalidChainID, &types.Block{ + check(utils.ErrInvalidChainID, &types.Block{ ParentHash: blocks[1][0].Hash, Position: types.Position{ ChainID: 100, diff --git a/core/nodeset-cache.go b/core/utils/nodeset-cache.go index 26e3d55..a8f8fe5 100644 --- a/core/nodeset-cache.go +++ b/core/utils/nodeset-cache.go @@ -15,7 +15,7 @@ // along with the dexon-consensus library. If not, see // <http://www.gnu.org/licenses/>. -package core +package utils import ( "errors" @@ -29,6 +29,8 @@ import ( var ( // ErrRoundNotReady means we got nil config. ErrRoundNotReady = errors.New("round is not ready") + // ErrInvalidChainID means the chain ID is unexpected. + ErrInvalidChainID = errors.New("invalid chain id") ) type sets struct { diff --git a/core/nodeset-cache_test.go b/core/utils/nodeset-cache_test.go index 828ef49..27c8c83 100644 --- a/core/nodeset-cache_test.go +++ b/core/utils/nodeset-cache_test.go @@ -15,16 +15,14 @@ // along with the dexon-consensus library. If not, see // <http://www.gnu.org/licenses/>. -package core +package utils import ( "testing" - "time" "github.com/dexon-foundation/dexon-consensus/common" "github.com/dexon-foundation/dexon-consensus/core/crypto" "github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa" - "github.com/dexon-foundation/dexon-consensus/core/test" "github.com/dexon-foundation/dexon-consensus/core/types" "github.com/stretchr/testify/suite" ) @@ -58,17 +56,6 @@ type NodeSetCacheTestSuite struct { suite.Suite } -func (s *NodeSetCacheTestSuite) TestGovernanceIntf() { - // NodeSetCacheInterface should let Governance implement it. - var gov Governance - _, pubKeys, err := test.NewKeys(7) - s.Require().NoError(err) - gov, err = test.NewGovernance(pubKeys, 250*time.Millisecond, ConfigRoundShift) - s.Require().NoError(err) - _, ok := gov.(NodeSetCacheInterface) - s.True(ok) -} - func (s *NodeSetCacheTestSuite) TestBasicUsage() { var ( nsIntf = &nsIntf{ diff --git a/integration_test/node.go b/integration_test/node.go index 4657d83..aa3a703 100644 --- a/integration_test/node.go +++ b/integration_test/node.go @@ -27,6 +27,7 @@ import ( "github.com/dexon-foundation/dexon-consensus/core/crypto" "github.com/dexon-foundation/dexon-consensus/core/test" "github.com/dexon-foundation/dexon-consensus/core/types" + "github.com/dexon-foundation/dexon-consensus/core/utils" ) type consensusEventType int @@ -162,7 +163,7 @@ func (n *Node) handleProposeBlock(when time.Time, payload interface{}) ( }) b, err := n.prepareBlock(pos.round, pos.chain, when) if err != nil { - if err == core.ErrInvalidChainID { + if err == utils.ErrInvalidChainID { // This chain is not included in this round, retry in next round. events = append(events, newProposeBlockEvent( n.ID, b.Position.Round+1, b.Position.ChainID, |