Skip to content

Commit

Permalink
Merge pull request ethereum#34 from QuarkChain/tm_w3q_resume
Browse files Browse the repository at this point in the history
tm resumes from most recent header
  • Loading branch information
qizhou authored Mar 8, 2022
2 parents 935f0f7 + e1b642a commit e48ff52
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
7 changes: 7 additions & 0 deletions consensus/tendermint/gov/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (g *Governance) EpochValidators(height uint64) []common.Address {
return header.NextValidators
}

// EpochValidatorPowers returns the current epoch validator powers that height belongs to
func (g *Governance) EpochValidatorPowers(height uint64) []uint64 {
// TODO: get real validators by calling contract
header := g.chain.GetHeaderByNumber(0)
return header.NextValidatorPowers
}

func (g *Governance) NextValidators(height uint64) []common.Address {
if height%g.epoch != 0 {
return []common.Address{}
Expand Down
25 changes: 19 additions & 6 deletions consensus/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,29 @@ func (c *Tendermint) Init(chain *core.BlockChain, makeBlock func(parent common.H
}
}()

genesis := chain.GetHeaderByNumber(0)
gcs := pbftconsensus.MakeGenesisChainState(
gov := gov.New(c.config.Epoch, chain)
block := chain.CurrentHeader()
number := block.Number.Uint64()
var lastValidators []common.Address
var lastValidatorPowers []uint64
if number != 0 {
lastValidators = gov.EpochValidators(number - 1)
lastValidatorPowers = gov.EpochValidatorPowers(number - 1)
}
gcs := pbftconsensus.MakeChainState(
c.config.NetworkID,
genesis.Time,
genesis.NextValidators,
types.U64ToI64Array(genesis.NextValidatorPowers),
number,
block.Hash(),
block.TimeMs,
gov.EpochValidators(number),
types.U64ToI64Array(gov.EpochValidatorPowers(number)),
gov.NextValidators(number),
types.U64ToI64Array(gov.NextValidatorPowers(number)),
lastValidators,
types.U64ToI64Array(lastValidatorPowers),
c.config.Epoch,
int64(c.config.ProposerRepetition),
)
gcs.LastBlockID = genesis.Hash()

// consensus
consensusState := pbftconsensus.NewConsensusState(
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.15

require (
github.com/Azure/azure-storage-blob-go v0.7.0
github.com/QuarkChain/go-minimal-pbft v0.0.0-20220306083522-1c8dc76afb94
github.com/QuarkChain/go-minimal-pbft v0.0.0-20220307211413-49a75ab4c3f2 // indirect
github.com/VictoriaMetrics/fastcache v1.6.0
github.com/aws/aws-sdk-go-v2 v1.2.0
github.com/aws/aws-sdk-go-v2/config v1.1.1
Expand Down Expand Up @@ -64,3 +64,5 @@ require (
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6
gopkg.in/urfave/cli.v1 v1.20.0
)

replace github.com/QuarkChain/go-minimal-pbft => ../go-minimal-pbft
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ github.com/QuarkChain/go-minimal-pbft v0.0.0-20220303075012-6084b729db36 h1:2SJS
github.com/QuarkChain/go-minimal-pbft v0.0.0-20220303075012-6084b729db36/go.mod h1:nC/gDMz8G2h+K5KGDiEwEGJ//D70G8mwOBgHraRUab8=
github.com/QuarkChain/go-minimal-pbft v0.0.0-20220306083522-1c8dc76afb94 h1:T2Ogn+k7G/0hybvozBlps68CWpfvczJ5MT+wgwqKJgQ=
github.com/QuarkChain/go-minimal-pbft v0.0.0-20220306083522-1c8dc76afb94/go.mod h1:nC/gDMz8G2h+K5KGDiEwEGJ//D70G8mwOBgHraRUab8=
github.com/QuarkChain/go-minimal-pbft v0.0.0-20220307211413-49a75ab4c3f2 h1:ChaJ8RHQxVn9aSm5ttGz15GEFKzwrhC52GKZnT1U7Ec=
github.com/QuarkChain/go-minimal-pbft v0.0.0-20220307211413-49a75ab4c3f2/go.mod h1:nC/gDMz8G2h+K5KGDiEwEGJ//D70G8mwOBgHraRUab8=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
Expand Down

0 comments on commit e48ff52

Please sign in to comment.