diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-09-17 17:45:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-17 17:45:49 +0800 |
commit | 8a908e98279d7e80978cd412057eddd4a6bbf06c (patch) | |
tree | 4e28f76fd95814978210c6f38ec4a09988e76957 | |
parent | cbf0012603deb6d2b8c257c079de98792f7b84cf (diff) | |
download | tangerine-consensus-8a908e98279d7e80978cd412057eddd4a6bbf06c.tar.gz tangerine-consensus-8a908e98279d7e80978cd412057eddd4a6bbf06c.tar.zst tangerine-consensus-8a908e98279d7e80978cd412057eddd4a6bbf06c.zip |
core: move blockdb into core package and minor change on governance interface (#110)
Since third party apps will possibly implement their only blockdb class,
it make sense for the interface to be in core.
Also add GetNumShards into the governance interface.
25 files changed, 43 insertions, 30 deletions
diff --git a/blockdb/interfaces.go b/core/blockdb/interfaces.go index fd176bc..fd176bc 100644 --- a/blockdb/interfaces.go +++ b/core/blockdb/interfaces.go diff --git a/blockdb/level-db.go b/core/blockdb/level-db.go index 79099c0..79099c0 100644 --- a/blockdb/level-db.go +++ b/core/blockdb/level-db.go diff --git a/blockdb/level-db_test.go b/core/blockdb/level-db_test.go index 06829f0..06829f0 100644 --- a/blockdb/level-db_test.go +++ b/core/blockdb/level-db_test.go diff --git a/blockdb/memory.go b/core/blockdb/memory.go index eeda477..eeda477 100644 --- a/blockdb/memory.go +++ b/core/blockdb/memory.go diff --git a/blockdb/memory_test.go b/core/blockdb/memory_test.go index 9a3cfa2..9a3cfa2 100644 --- a/blockdb/memory_test.go +++ b/core/blockdb/memory_test.go diff --git a/core/compaction-chain.go b/core/compaction-chain.go index 243bda0..9ac52b0 100644 --- a/core/compaction-chain.go +++ b/core/compaction-chain.go @@ -24,8 +24,8 @@ import ( "sync" "time" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/dexon-foundation/dexon-consensus-core/crypto" ) diff --git a/core/compaction-chain_test.go b/core/compaction-chain_test.go index 46d4e10..ae08ac0 100644 --- a/core/compaction-chain_test.go +++ b/core/compaction-chain_test.go @@ -21,8 +21,8 @@ import ( "testing" "time" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/dexon-foundation/dexon-consensus-core/crypto/eth" "github.com/stretchr/testify/suite" diff --git a/core/consensus.go b/core/consensus.go index 4b92994..5e56ab9 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -25,8 +25,8 @@ import ( "sync" "time" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/dexon-foundation/dexon-consensus-core/crypto" ) @@ -145,7 +145,7 @@ func NewConsensus( // Setup acking by information returned from Governace. rb := newReliableBroadcast() - rb.setChainNum(gov.GetChainNumber()) + rb.setChainNum(gov.GetNumChains()) for vID := range validatorSet { rb.addValidator(vID) } @@ -160,7 +160,7 @@ func NewConsensus( to := newTotalOrdering( uint64(gov.GetTotalOrderingK()), uint64(float32(len(validatorSet)-1)*gov.GetPhiRatio()+1), - gov.GetChainNumber()) + gov.GetNumChains()) con := &Consensus{ ID: types.NewValidatorID(prv.PublicKey()), @@ -179,9 +179,9 @@ func NewConsensus( ctxCancel: ctxCancel, } - con.baModules = make([]*agreement, con.gov.GetChainNumber()) - con.receivers = make([]*consensusReceiver, con.gov.GetChainNumber()) - for i := uint32(0); i < con.gov.GetChainNumber(); i++ { + con.baModules = make([]*agreement, con.gov.GetNumChains()) + con.receivers = make([]*consensusReceiver, con.gov.GetNumChains()) + for i := uint32(0); i < con.gov.GetNumChains(); i++ { chainID := i con.receivers[chainID] = &consensusReceiver{ consensus: con, @@ -208,8 +208,8 @@ func NewConsensus( // Run starts running DEXON Consensus. func (con *Consensus) Run() { - ticks := make([]chan struct{}, 0, con.gov.GetChainNumber()) - for i := uint32(0); i < con.gov.GetChainNumber(); i++ { + ticks := make([]chan struct{}, 0, con.gov.GetNumChains()) + for i := uint32(0); i < con.gov.GetNumChains(); i++ { tick := make(chan struct{}) ticks = append(ticks, tick) go con.runBA(i, tick) diff --git a/core/consensus_test.go b/core/consensus_test.go index 313600a..1e97993 100644 --- a/core/consensus_test.go +++ b/core/consensus_test.go @@ -22,8 +22,8 @@ import ( "testing" "time" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/dexon-foundation/dexon-consensus-core/crypto/eth" diff --git a/core/interfaces.go b/core/interfaces.go index aa4756e..68f210e 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -87,8 +87,11 @@ type Governance interface { // Get block proposing interval (in milliseconds). GetBlockProposingInterval() int - // Get Number of Chains. - GetChainNumber() uint32 + // Get Number of shards. + GetNumShards() uint32 + + // Get Number of chains. + GetNumChains() uint32 // Get Genesis CRS. GetGenesisCRS() string diff --git a/core/reliable-broadcast_test.go b/core/reliable-broadcast_test.go index bced96a..b1fc672 100644 --- a/core/reliable-broadcast_test.go +++ b/core/reliable-broadcast_test.go @@ -27,8 +27,8 @@ import ( "github.com/stretchr/testify/suite" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) diff --git a/core/test/blocks-generator.go b/core/test/blocks-generator.go index 64ddfe2..93867f1 100644 --- a/core/test/blocks-generator.go +++ b/core/test/blocks-generator.go @@ -23,8 +23,8 @@ import ( "math/rand" "time" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) diff --git a/core/test/blocks-generator_test.go b/core/test/blocks-generator_test.go index d46a082..e607796 100644 --- a/core/test/blocks-generator_test.go +++ b/core/test/blocks-generator_test.go @@ -21,8 +21,8 @@ import ( "sort" "testing" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/stretchr/testify/suite" ) diff --git a/core/test/governance.go b/core/test/governance.go index 0e5c249..64ca39f 100644 --- a/core/test/governance.go +++ b/core/test/governance.go @@ -85,8 +85,13 @@ func (g *Governance) GetPhiRatio() float32 { return 0.667 } -// GetChainNumber returns the number of chains. -func (g *Governance) GetChainNumber() uint32 { +// GetNumShards returns the number of shards. +func (g *Governance) GetNumShards() uint32 { + return 1 +} + +// GetNumChains returns the number of chains. +func (g *Governance) GetNumChains() uint32 { return uint32(len(g.Validators)) } diff --git a/core/test/interface.go b/core/test/interface.go index 9932262..0dc2382 100644 --- a/core/test/interface.go +++ b/core/test/interface.go @@ -18,7 +18,7 @@ package test import ( - "github.com/dexon-foundation/dexon-consensus-core/blockdb" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) diff --git a/core/test/revealer.go b/core/test/revealer.go index 95eeb7c..b8eb9b4 100644 --- a/core/test/revealer.go +++ b/core/test/revealer.go @@ -22,8 +22,8 @@ import ( "sort" "time" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) diff --git a/core/test/revealer_test.go b/core/test/revealer_test.go index 032cab3..16d3b18 100644 --- a/core/test/revealer_test.go +++ b/core/test/revealer_test.go @@ -20,8 +20,8 @@ package test import ( "testing" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/stretchr/testify/suite" ) diff --git a/core/test/stopper.go b/core/test/stopper.go index da4d205..7c75958 100644 --- a/core/test/stopper.go +++ b/core/test/stopper.go @@ -20,7 +20,7 @@ package test import ( "sync" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) diff --git a/core/test/stopper_test.go b/core/test/stopper_test.go index 2abd503..9a0e430 100644 --- a/core/test/stopper_test.go +++ b/core/test/stopper_test.go @@ -21,8 +21,8 @@ import ( "testing" "time" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/stretchr/testify/suite" ) diff --git a/core/total-ordering_test.go b/core/total-ordering_test.go index f0d2e34..d6805b8 100644 --- a/core/total-ordering_test.go +++ b/core/total-ordering_test.go @@ -22,8 +22,8 @@ import ( "strings" "testing" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/stretchr/testify/suite" diff --git a/integration_test/non-byzantine_test.go b/integration_test/non-byzantine_test.go index afda9b4..a5ecff6 100644 --- a/integration_test/non-byzantine_test.go +++ b/integration_test/non-byzantine_test.go @@ -21,7 +21,7 @@ import ( "testing" "time" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/stretchr/testify/suite" diff --git a/integration_test/utils.go b/integration_test/utils.go index 7371223..de7e6ab 100644 --- a/integration_test/utils.go +++ b/integration_test/utils.go @@ -1,7 +1,7 @@ package integration import ( - "github.com/dexon-foundation/dexon-consensus-core/blockdb" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/dexon-foundation/dexon-consensus-core/crypto" diff --git a/integration_test/validator.go b/integration_test/validator.go index 5909b46..a110ab0 100644 --- a/integration_test/validator.go +++ b/integration_test/validator.go @@ -22,9 +22,9 @@ import ( "sort" "time" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/dexon-foundation/dexon-consensus-core/crypto" diff --git a/simulation/governance.go b/simulation/governance.go index 5220ae5..44f679d 100644 --- a/simulation/governance.go +++ b/simulation/governance.go @@ -85,8 +85,13 @@ func (g *simGovernance) GetBlockProposingInterval() int { return 0 } -// GetChainNumber returns number of chain. -func (g *simGovernance) GetChainNumber() uint32 { +// GetNumShards returns number of shards. +func (g *simGovernance) GetNumShards() uint32 { + return 1 +} + +// GetNumChains returns number of chains. +func (g *simGovernance) GetNumChains() uint32 { return g.chainNum } diff --git a/simulation/validator.go b/simulation/validator.go index 483912b..137c2c0 100644 --- a/simulation/validator.go +++ b/simulation/validator.go @@ -22,9 +22,9 @@ import ( "sort" "time" - "github.com/dexon-foundation/dexon-consensus-core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core" + "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/dexon-foundation/dexon-consensus-core/crypto" "github.com/dexon-foundation/dexon-consensus-core/simulation/config" |