Skip to content

Commit

Permalink
Merge pull request ethereum#292 from nextyio/config
Browse files Browse the repository at this point in the history
Config and params for the next hardfork
  • Loading branch information
Zergity authored Sep 18, 2019
2 parents 9eae657 + a7ed892 commit 64b9d34
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 94 deletions.
19 changes: 3 additions & 16 deletions cmd/puppeth/wizard_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ func (w *wizard) makeGenesis() {
genesis.GasLimit = 42000000
genesis.Difficulty = big.NewInt(1)
genesis.Config.Dccs = &params.DccsConfig{
Period: 2,
Epoch: 30000,
Contract: common.HexToAddress("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"),
Period: 2,
Epoch: 30000,
// Stake params
StakeRequire: 100,
StakeLockHeight: 24 * 60 * 60 / 2,
Expand Down Expand Up @@ -178,12 +177,6 @@ func (w *wizard) makeGenesis() {
fmt.Printf("How many blocks should epoch take after the Thang Long hardfork? (default = %v)\n", genesis.Config.Dccs.ThangLongEpoch)
genesis.Config.Dccs.ThangLongEpoch = uint64(w.readDefaultInt(int(genesis.Config.Dccs.ThangLongEpoch)))

fmt.Println()
fmt.Printf("Which nexty governance smart contract address? (default = %v)\n", genesis.Config.Dccs.Contract.Hex())
if address := w.readAddress(); address != nil {
genesis.Config.Dccs.Contract = *address
}

fmt.Println()
fmt.Printf("How many NTF is required to join sealing? (default = %v)\n", genesis.Config.Dccs.StakeRequire)
genesis.Config.Dccs.StakeRequire = uint64(w.readDefaultInt(int(genesis.Config.Dccs.StakeRequire)))
Expand Down Expand Up @@ -267,7 +260,7 @@ func (w *wizard) makeGenesis() {
// Read the address of the account to fund
if address := w.readAddress(); address != nil {
genesis.Alloc[*address] = core.GenesisAccount{
Balance: new(big.Int).Lsh(big.NewInt(1), 256-7), // 2^256 / 128 (allow many pre-funds without balance overflows)
Balance: common.Big1e27,
}
continue
}
Expand Down Expand Up @@ -390,12 +383,6 @@ func (w *wizard) manageGenesis() {
fmt.Println()
fmt.Printf("Which block should ThangLong come into effect? (default = %v)\n", w.conf.Genesis.Config.Dccs.ThangLongBlock)
w.conf.Genesis.Config.Dccs.ThangLongBlock = w.readDefaultBigInt(w.conf.Genesis.Config.Dccs.ThangLongBlock)

fmt.Println()
fmt.Printf("Which nexty governance smart contract address? (default = %v)\n", w.conf.Genesis.Config.Dccs.Contract.Hex())
if address := w.readAddress(); address != nil {
w.conf.Genesis.Config.Dccs.Contract = *address
}
}

out, _ := json.MarshalIndent(w.conf.Genesis.Config, "", " ")
Expand Down
1 change: 1 addition & 0 deletions common/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
Big1000 = big.NewInt(1000)
Big1e12 = big.NewInt(1e12)
Big1e24 = new(big.Int).Mul(Big1e12, Big1e12)
Big1e27 = new(big.Int).Mul(Big1e24, Big1000)
)

var (
Expand Down
12 changes: 6 additions & 6 deletions consensus/dccs/1_dccs.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ func (d *Dccs) getStateSnapshot(chain consensus.ChainReader, header *types.Heade
log.Trace("Snapshot state not available", "number", number, "err", err)
return nil, errSnapshotNotAvailable
}
size := state.GetCodeSize(chain.Config().Dccs.Contract)
size := state.GetCodeSize(params.GovernanceAddress)
if size <= 0 || state.Error() != nil {
log.Trace("Snapshot contract state not available", "number", number, "err", state.Error())
return nil, errSnapshotNotAvailable
}
index := common.BigToHash(common.Big0)
result := state.GetState(chain.Config().Dccs.Contract, index)
result := state.GetState(params.GovernanceAddress, index)
var length int64
if (result == common.Hash{}) {
length = 0
Expand All @@ -245,7 +245,7 @@ func (d *Dccs) getStateSnapshot(chain consensus.ChainReader, header *types.Heade
key := crypto.Keccak256Hash(hexutil.MustDecode(index.String()))
for i := 0; i < len(signers); i++ {
log.Trace("key hash", "key", key)
singer := state.GetState(chain.Config().Dccs.Contract, key)
singer := state.GetState(params.GovernanceAddress, key)
signers[i] = common.HexToAddress(singer.Hex())
key = key.Plus()
}
Expand Down Expand Up @@ -441,7 +441,7 @@ func (d *Dccs) prepareBeneficiary(header *types.Header, chain consensus.ChainRea
if err != nil {
log.Error("Chain state not available", "number", number, "err", err)
} else if state != nil {
hash := state.GetState(chain.Config().Dccs.Contract, key)
hash := state.GetState(params.GovernanceAddress, key)
if (hash != common.Hash{}) {
header.Coinbase = common.HexToAddress(hash.Hex())
return
Expand All @@ -461,7 +461,7 @@ func (d *Dccs) prepareBeneficiary(header *types.Header, chain consensus.ChainRea
return
}

hash := state.GetState(chain.Config().Dccs.Contract, key)
hash := state.GetState(params.GovernanceAddress, key)
if (hash != common.Hash{}) {
header.Coinbase = common.HexToAddress(hash.Hex())
}
Expand Down Expand Up @@ -743,7 +743,7 @@ func deployConsensusContracts(state *state.StateDB, chainConfig *params.ChainCon
return err
}
// Deploy or update
deployContract(state, chainConfig.Dccs.Contract, code, storage, true)
deployContract(state, params.GovernanceAddress, code, storage, true)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions consensus/dccs/2_dccs.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (c *Context) prepareBeneficiary2(header *types.Header) {
// try the current active state first
state, err := c.chain.State()
if err == nil && state != nil {
hash := state.GetState(c.chain.Config().Dccs.Contract, key)
hash := state.GetState(params.GovernanceAddress, key)
if (hash != common.Hash{}) {
header.Coinbase = common.HexToAddress(hash.Hex())
return
Expand Down Expand Up @@ -539,7 +539,7 @@ func (c *Context) initialize2(header *types.Header, state *state.StateDB) (types
return nil, nil, nil
}

medianPrice, err := c.CalcMedianPrice(header.Number.Uint64() - params.CanonicalDepth)
medianPrice, err := c.CalcMedianPrice(header.Number.Uint64() - 1)
if err != nil {
log.Trace("Failed to calculate canonical median price", "err", err, "number", header.Number)
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/dccs/2_logfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
)

Expand Down Expand Up @@ -76,7 +77,7 @@ var _ filters.SimpleBackend = (*logFilterBackend)(nil)
// the requests kept as is.
func (c *Context) fetchSealerApplications(header *types.Header) ([]SealerApplication, error) {
logs, err := filters.BlockLogs(header,
[]common.Address{c.engine.config.Contract},
[]common.Address{params.GovernanceAddress},
[][]common.Hash{{joinedTopic, leftTopic}},
&logFilterBackend{
chain: c.chain,
Expand Down
2 changes: 1 addition & 1 deletion consensus/dccs/2_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (a ByPrice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (c *Context) CalcMedianPrice(number uint64) (*Price, error) {
if !c.engine.config.IsPriceBlock(number) {
// not a price block
return nil, errors.New("Not a price block")
return nil, nil
}
if number > c.chain.CurrentHeader().Number.Uint64() {
return nil, errors.New("Block number too high")
Expand Down
4 changes: 2 additions & 2 deletions consensus/dccs/dccs.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,14 @@ func (d *Dccs) FinalizeAndAssemble(chain consensus.ChainReader, header *types.He
// with.
func (d *Dccs) Authorize(signer common.Address, signFn SignerFn, state *state.StateDB, header *types.Header) {
if d.config.IsThangLong(header.Number) {
size := state.GetCodeSize(d.config.Contract)
size := state.GetCodeSize(params.GovernanceAddress)
log.Info("smart contract size", "size", size)
if size > 0 && state.Error() == nil {
// Get token holder from coinbase
index := common.BigToHash(common.Big1).String()[2:]
coinbase := "0x000000000000000000000000" + signer.String()[2:]
key := crypto.Keccak256Hash(hexutil.MustDecode(coinbase + index))
result := state.GetState(d.config.Contract, key)
result := state.GetState(params.GovernanceAddress, key)

if (result == common.Hash{}) {
log.Warn("Validator is not in activation sealer set")
Expand Down
Loading

0 comments on commit 64b9d34

Please sign in to comment.