diff options
-rw-r--r-- | consensus/dexcon/dexcon.go | 3 | ||||
-rw-r--r-- | core/genesis.go | 1 | ||||
-rw-r--r-- | params/config.go | 7 | ||||
-rw-r--r-- | params/gen_dexcon_config.go | 103 | ||||
-rw-r--r-- | test/genesis.json | 3 |
5 files changed, 114 insertions, 3 deletions
diff --git a/consensus/dexcon/dexcon.go b/consensus/dexcon/dexcon.go index f7857c070..46090b757 100644 --- a/consensus/dexcon/dexcon.go +++ b/consensus/dexcon/dexcon.go @@ -106,8 +106,7 @@ func (d *Dexcon) Prepare(chain consensus.ChainReader, header *types.Header) erro // 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 - blockReward := big.NewInt(1e+18) - reward := new(big.Int).Div(blockReward, new(big.Int).SetUint64(uint64(d.config.NumChains))) + reward := new(big.Int).Div(d.config.BlockReward, new(big.Int).SetUint64(uint64(d.config.NumChains))) state.AddBalance(header.Coinbase, reward) header.Root = state.IntermediateRoot(true) diff --git a/core/genesis.go b/core/genesis.go index eaca53673..a176deb00 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -255,6 +255,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block { govStateHelper := vm.GovernanceStateHelper{statedb} for addr, account := range g.Alloc { + fmt.Println(account) statedb.AddBalance(addr, new(big.Int).Sub(account.Balance, account.Staked)) statedb.SetCode(addr, account.Code) statedb.SetNonce(addr, account.Nonce) diff --git a/params/config.go b/params/config.go index fc02c3aa3..fdf716661 100644 --- a/params/config.go +++ b/params/config.go @@ -21,6 +21,7 @@ import ( "math/big" "github.com/dexon-foundation/dexon/common" + "github.com/dexon-foundation/dexon/common/math" ) // Genesis hashes to enforce below configs on. @@ -227,6 +228,8 @@ func (c *CliqueConfig) String() string { return "clique" } +//go:generate gencodec -type DexconConfig -field-override dexconConfigSpecMarshaling -out gen_dexcon_config.go + // DexconConfig is the consensus engine configs for DEXON consensus. type DexconConfig struct { GenesisCRSText string `json:"genesisCRSText"` @@ -243,6 +246,10 @@ type DexconConfig struct { BlockReward *big.Int `json:"blockReward"` } +type dexconConfigSpecMarshaling struct { + BlockReward *math.HexOrDecimal256 +} + // String implements the stringer interface, returning the consensus engine details. func (d *DexconConfig) String() string { return fmt.Sprintf("{GenesisCRSText: %v NumChains: %v LambdaBA: %v LambdaDKG: %v K: %v PhiRatio: %v NotarySetSize: %v DKGSetSize: %v RoundInterval: %v MinBlockInterval: %v MaxBlockInterval: %v BlockReward: %v", diff --git a/params/gen_dexcon_config.go b/params/gen_dexcon_config.go new file mode 100644 index 000000000..bd169584f --- /dev/null +++ b/params/gen_dexcon_config.go @@ -0,0 +1,103 @@ +// Code generated by github.com/fjl/gencodec. DO NOT EDIT. + +package params + +import ( + "encoding/json" + "math/big" + + "github.com/dexon-foundation/dexon/common/math" +) + +var _ = (*dexconConfigSpecMarshaling)(nil) + +// MarshalJSON marshals as JSON. +func (d DexconConfig) MarshalJSON() ([]byte, error) { + type DexconConfig struct { + GenesisCRSText string `json:"genesisCRSText"` + NumChains uint32 `json:"numChains"` + LambdaBA uint64 `json:"lambdaBA"` + LambdaDKG uint64 `json:"lambdaDKG"` + K int `json:"k"` + PhiRatio float32 `json:"phiRatio"` + NotarySetSize uint32 `json:"notarySetSize"` + DKGSetSize uint32 `json:"dkgSetSize"` + RoundInterval uint64 `json:"roundInterval"` + MinBlockInterval uint64 `json:"minBlockInterval"` + MaxBlockInterval uint64 `json:"maxBlockInterval"` + BlockReward *math.HexOrDecimal256 `json:"blockReward"` + } + var enc DexconConfig + enc.GenesisCRSText = d.GenesisCRSText + enc.NumChains = d.NumChains + enc.LambdaBA = d.LambdaBA + enc.LambdaDKG = d.LambdaDKG + enc.K = d.K + enc.PhiRatio = d.PhiRatio + enc.NotarySetSize = d.NotarySetSize + enc.DKGSetSize = d.DKGSetSize + enc.RoundInterval = d.RoundInterval + enc.MinBlockInterval = d.MinBlockInterval + enc.MaxBlockInterval = d.MaxBlockInterval + enc.BlockReward = (*math.HexOrDecimal256)(d.BlockReward) + return json.Marshal(&enc) +} + +// UnmarshalJSON unmarshals from JSON. +func (d *DexconConfig) UnmarshalJSON(input []byte) error { + type DexconConfig struct { + GenesisCRSText *string `json:"genesisCRSText"` + NumChains *uint32 `json:"numChains"` + LambdaBA *uint64 `json:"lambdaBA"` + LambdaDKG *uint64 `json:"lambdaDKG"` + K *int `json:"k"` + PhiRatio *float32 `json:"phiRatio"` + NotarySetSize *uint32 `json:"notarySetSize"` + DKGSetSize *uint32 `json:"dkgSetSize"` + RoundInterval *uint64 `json:"roundInterval"` + MinBlockInterval *uint64 `json:"minBlockInterval"` + MaxBlockInterval *uint64 `json:"maxBlockInterval"` + BlockReward *math.HexOrDecimal256 `json:"blockReward"` + } + var dec DexconConfig + if err := json.Unmarshal(input, &dec); err != nil { + return err + } + if dec.GenesisCRSText != nil { + d.GenesisCRSText = *dec.GenesisCRSText + } + if dec.NumChains != nil { + d.NumChains = *dec.NumChains + } + if dec.LambdaBA != nil { + d.LambdaBA = *dec.LambdaBA + } + if dec.LambdaDKG != nil { + d.LambdaDKG = *dec.LambdaDKG + } + if dec.K != nil { + d.K = *dec.K + } + if dec.PhiRatio != nil { + d.PhiRatio = *dec.PhiRatio + } + if dec.NotarySetSize != nil { + d.NotarySetSize = *dec.NotarySetSize + } + if dec.DKGSetSize != nil { + d.DKGSetSize = *dec.DKGSetSize + } + if dec.RoundInterval != nil { + d.RoundInterval = *dec.RoundInterval + } + if dec.MinBlockInterval != nil { + d.MinBlockInterval = *dec.MinBlockInterval + } + if dec.MaxBlockInterval != nil { + d.MaxBlockInterval = *dec.MaxBlockInterval + } + if dec.BlockReward != nil { + d.BlockReward = (*big.Int)(dec.BlockReward) + } + return nil +} diff --git a/test/genesis.json b/test/genesis.json index 2c6b51d20..f5bf4036b 100644 --- a/test/genesis.json +++ b/test/genesis.json @@ -17,7 +17,8 @@ "dkgSetSize": 4, "roundInterval": 99999999999, "minBlockInterval": 900, - "maxBlockInterval": 1100 + "maxBlockInterval": 1100, + "blockReward": "1000000000000000000" } }, "nonce": "0x42", |