aboutsummaryrefslogtreecommitdiffstats
path: root/consensus
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-10-19 18:52:38 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:50 +0800
commit00e8f2d99b3c6b27d8047712baf5bbb6150dc273 (patch)
treeb36879b60e89210e664a7007d08fcd5a990e613d /consensus
parentb52b1b2106f075260674660638aa60fe5ec81f87 (diff)
downloaddexon-00e8f2d99b3c6b27d8047712baf5bbb6150dc273.tar
dexon-00e8f2d99b3c6b27d8047712baf5bbb6150dc273.tar.gz
dexon-00e8f2d99b3c6b27d8047712baf5bbb6150dc273.tar.bz2
dexon-00e8f2d99b3c6b27d8047712baf5bbb6150dc273.tar.lz
dexon-00e8f2d99b3c6b27d8047712baf5bbb6150dc273.tar.xz
dexon-00e8f2d99b3c6b27d8047712baf5bbb6150dc273.tar.zst
dexon-00e8f2d99b3c6b27d8047712baf5bbb6150dc273.zip
consensus: dexcon: fetch config from state
Diffstat (limited to 'consensus')
-rw-r--r--consensus/dexcon/dexcon.go24
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
}