Merge pull request #412 from dinhln89/rollback

Add rollback flag command for rollback chain at block hash.
This commit is contained in:
Tuna 2019-01-22 09:22:45 +07:00 committed by GitHub
commit ff61e1b301
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 30 additions and 4 deletions

View file

@ -157,6 +157,11 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) {
common.IsTestnet = true
}
// Check rollback hash exist.
if rollbackHash := ctx.GlobalString(utils.RollbackFlag.Name); rollbackHash != "" {
common.RollbackHash = common.HexToHash(rollbackHash)
}
// read passwords from environment
passwords := []string{}
for _, env := range cfg.Account.Passwords {

View file

@ -123,6 +123,7 @@ var (
configFileFlag,
utils.AnnounceTxsFlag,
utils.StoreRewardFlag,
utils.RollbackFlag,
}
rpcFlags = []cli.Flag{

View file

@ -112,6 +112,12 @@ func NewApp(gitCommit, usage string) *cli.App {
// are the same for all commands.
var (
// Tomo flags.
RollbackFlag = cli.StringFlag{
Name: "rollback",
Usage: "Rollback chain at hash",
Value: "",
}
// General settings
AnnounceTxsFlag = cli.BoolFlag{
Name: "announce-txs",

View file

@ -23,3 +23,4 @@ const (
var TIP2019Block = big.NewInt(1050000)
var IsTestnet bool = false
var StoreRewardFolder string
var RollbackHash Hash

View file

@ -1,4 +1,5 @@
package contracts
//
//import (
// "fmt"

View file

@ -17,11 +17,11 @@ package validator
import (
"context"
"encoding/json"
"math/big"
"math/rand"
"testing"
"time"
"math/rand"
"encoding/json"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"

View file

@ -10,7 +10,7 @@ import (
)
var (
slotValidatorMapping = map[string]uint64{
slotValidatorMapping = map[string]uint64{
"withdrawsState": 0,
"validatorsState": 1,
"voters": 2,

View file

@ -170,6 +170,17 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
}
eth.txPool = core.NewTxPool(config.TxPool, eth.chainConfig, eth.blockchain)
if common.RollbackHash != common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000") {
curBlock := eth.blockchain.CurrentBlock()
prevBlock := eth.blockchain.GetBlockByHash(common.RollbackHash)
if curBlock.NumberU64() > prevBlock.NumberU64() {
for ; curBlock != nil && curBlock.NumberU64() != prevBlock.NumberU64(); curBlock = eth.blockchain.GetBlock(curBlock.ParentHash(), curBlock.NumberU64()-1) {
eth.blockchain.Rollback([]common.Hash{curBlock.Hash()})
}
}
}
if eth.protocolManager, err = NewProtocolManager(eth.chainConfig, config.SyncMode, config.NetworkId, eth.eventMux, eth.txPool, eth.engine, eth.blockchain, chainDb); err != nil {
return nil, err
}

View file

@ -216,6 +216,7 @@ func (c *ChainConfig) IsConstantinople(num *big.Int) bool {
func (c *ChainConfig) IsTIP2019(num *big.Int) bool {
return isForked(common.TIP2019Block, num)
}
// GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice).
//
// The returned GasTable's fields shouldn't, under any circumstances, be changed.