Skip to content

Commit

Permalink
Merge pull request ethereum#412 from dinhln89/rollback
Browse files Browse the repository at this point in the history
Add rollback flag command for rollback chain at block hash.
  • Loading branch information
ngtuna committed Jan 22, 2019
2 parents 0c19b3b + 19c6b84 commit ff61e1b
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/tomo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions cmd/tomo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ var (
configFileFlag,
utils.AnnounceTxsFlag,
utils.StoreRewardFlag,
utils.RollbackFlag,
}

rpcFlags = []cli.Flag{
Expand Down
6 changes: 6 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ const (
var TIP2019Block = big.NewInt(1050000)
var IsTestnet bool = false
var StoreRewardFolder string
var RollbackHash Hash
1 change: 1 addition & 0 deletions contracts/test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package contracts

//
//import (
// "fmt"
Expand Down
6 changes: 3 additions & 3 deletions contracts/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -248,4 +248,4 @@ func GetCandidatesOwnerBySigner(validator *contractValidator.TomoValidator, sign
}

return owner
}
}
2 changes: 1 addition & 1 deletion contracts/validatorReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

var (
slotValidatorMapping = map[string]uint64{
slotValidatorMapping = map[string]uint64{
"withdrawsState": 0,
"validatorsState": 1,
"voters": 2,
Expand Down
11 changes: 11 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ff61e1b

Please sign in to comment.