Add rollback flag command for rollback chain at block hash.

This commit is contained in:
DinhLN 2019-01-17 13:59:02 +07:00
parent fe448f6a50
commit 19c6b8410e
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 common.IsTestnet = true
} }
// Check rollback hash exist.
if rollbackHash := ctx.GlobalString(utils.RollbackFlag.Name); rollbackHash != "" {
common.RollbackHash = common.HexToHash(rollbackHash)
}
// read passwords from environment // read passwords from environment
passwords := []string{} passwords := []string{}
for _, env := range cfg.Account.Passwords { for _, env := range cfg.Account.Passwords {

View file

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

View file

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

View file

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

View file

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

View file

@ -17,11 +17,11 @@ package validator
import ( import (
"context" "context"
"encoding/json"
"math/big" "math/big"
"math/rand"
"testing" "testing"
"time" "time"
"math/rand"
"encoding/json"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
@ -248,4 +248,4 @@ func GetCandidatesOwnerBySigner(validator *contractValidator.TomoValidator, sign
} }
return owner return owner
} }

View file

@ -10,7 +10,7 @@ import (
) )
var ( var (
slotValidatorMapping = map[string]uint64{ slotValidatorMapping = map[string]uint64{
"withdrawsState": 0, "withdrawsState": 0,
"validatorsState": 1, "validatorsState": 1,
"voters": 2, "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) 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 { 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 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 { func (c *ChainConfig) IsTIP2019(num *big.Int) bool {
return isForked(common.TIP2019Block, num) return isForked(common.TIP2019Block, num)
} }
// GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice). // 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. // The returned GasTable's fields shouldn't, under any circumstances, be changed.