mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
Merge pull request #412 from dinhln89/rollback
Add rollback flag command for rollback chain at block hash.
This commit is contained in:
commit
ff61e1b301
9 changed files with 30 additions and 4 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ var (
|
|||
configFileFlag,
|
||||
utils.AnnounceTxsFlag,
|
||||
utils.StoreRewardFlag,
|
||||
utils.RollbackFlag,
|
||||
}
|
||||
|
||||
rpcFlags = []cli.Flag{
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -23,3 +23,4 @@ const (
|
|||
var TIP2019Block = big.NewInt(1050000)
|
||||
var IsTestnet bool = false
|
||||
var StoreRewardFolder string
|
||||
var RollbackHash Hash
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
package contracts
|
||||
|
||||
//
|
||||
//import (
|
||||
// "fmt"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue