diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-19 18:52:38 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2018-12-19 20:54:27 +0800 |
commit | 35c4bfe0326eecc3d2feeb592b6a0057038ebb3e (patch) | |
tree | 371e357b2135fc5fb3f3e1609fae31f015c1fc6b /consensus/dexcon | |
parent | 84c85fb081a0a821077e94c66beb391fa6fa86c9 (diff) | |
download | dexon-35c4bfe0326eecc3d2feeb592b6a0057038ebb3e.tar dexon-35c4bfe0326eecc3d2feeb592b6a0057038ebb3e.tar.gz dexon-35c4bfe0326eecc3d2feeb592b6a0057038ebb3e.tar.bz2 dexon-35c4bfe0326eecc3d2feeb592b6a0057038ebb3e.tar.lz dexon-35c4bfe0326eecc3d2feeb592b6a0057038ebb3e.tar.xz dexon-35c4bfe0326eecc3d2feeb592b6a0057038ebb3e.tar.zst dexon-35c4bfe0326eecc3d2feeb592b6a0057038ebb3e.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 } |