diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-19 18:52:38 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:23:39 +0800 |
commit | 0e12c9284efdf72a376f75f180bac7968d6fb382 (patch) | |
tree | 1b06f8f9483bff246dbeba12c7445780a595b21a /consensus/dexcon | |
parent | 93563f41410b964454f23229cfabe1ec1ba735f5 (diff) | |
download | go-tangerine-0e12c9284efdf72a376f75f180bac7968d6fb382.tar go-tangerine-0e12c9284efdf72a376f75f180bac7968d6fb382.tar.gz go-tangerine-0e12c9284efdf72a376f75f180bac7968d6fb382.tar.bz2 go-tangerine-0e12c9284efdf72a376f75f180bac7968d6fb382.tar.lz go-tangerine-0e12c9284efdf72a376f75f180bac7968d6fb382.tar.xz go-tangerine-0e12c9284efdf72a376f75f180bac7968d6fb382.tar.zst go-tangerine-0e12c9284efdf72a376f75f180bac7968d6fb382.zip |
consensus: dexcon: fetch config from state
Diffstat (limited to 'consensus/dexcon')
-rw-r--r-- | consensus/dexcon/dexcon.go | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/consensus/dexcon/dexcon.go b/consensus/dexcon/dexcon.go index 46090b757..e636108f8 100644 --- a/consensus/dexcon/dexcon.go +++ b/consensus/dexcon/dexcon.go @@ -27,21 +27,26 @@ import ( "github.com/dexon-foundation/dexon/rpc" ) -// Config is the configuration for DEXON consensus. -type Config struct { +type ConfigurationFetcher interface { + DexconConfiguration(round uint64) *params.DexconConfig } // Dexcon is a delegated proof-of-stake consensus engine. type Dexcon struct { - config *params.DexconConfig + configFetcher ConfigurationFetcher } // New creates a Clique proof-of-authority consensus engine with the initial // signers set to the ones provided by the user. -func New(config *params.DexconConfig) *Dexcon { - return &Dexcon{ - config: config, - } +func New() *Dexcon { + return &Dexcon{} +} + +// SetConfigFetcher sets the config fetcher for Dexcon. The reason this is not +// passed in the New() method is to bypass cycle dependencies when initializing +// dex backend. +func (d *Dexcon) SetConfigFetcher(fetcher ConfigurationFetcher) { + d.configFetcher = fetcher } // Author implements consensus.Engine, returning the Ethereum address recovered @@ -105,11 +110,10 @@ func (d *Dexcon) Prepare(chain consensus.ChainReader, header *types.Header) erro // Finalize implements consensus.Engine, ensuring no uncles are set, nor block // rewards given, and returns the final block. func (d *Dexcon) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) { - // TODO(Bojie): remove it and get value from config - reward := new(big.Int).Div(d.config.BlockReward, new(big.Int).SetUint64(uint64(d.config.NumChains))) + config := d.configFetcher.DexconConfiguration(header.Position.Round) + reward := new(big.Int).Div(config.BlockReward, big.NewInt(int64(config.NumChains))) state.AddBalance(header.Coinbase, reward) header.Root = state.IntermediateRoot(true) - return types.NewBlock(header, txs, uncles, receipts), nil } |