mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Add discard cli to discard synced blocks
The command is useful in case the synchronizer reaches an invalid state and you want to roll back a few blocks and try again (maybe with some fixes in the code).
This commit is contained in:
@@ -117,7 +117,16 @@ Generate a new BabyJubJub key pair:
|
|||||||
./node --mode coord --cfg cfg.buidler.toml genbjj
|
./node --mode coord --cfg cfg.buidler.toml genbjj
|
||||||
```
|
```
|
||||||
|
|
||||||
Wipe the entier SQL database (this will destroy all synchronized and pool data):
|
Wipe the entier SQL database (this will destroy all synchronized and pool
|
||||||
|
data):
|
||||||
```
|
```
|
||||||
./node --mode coord --cfg cfg.buidler.toml wipesql
|
./node --mode coord --cfg cfg.buidler.toml wipesql
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Discard all synchronized blocks and associated state up to a given block
|
||||||
|
number. This command is useful in case the synchronizer reaches an invalid
|
||||||
|
state and you want to roll back a few blocks and try again (maybe with some
|
||||||
|
fixes in the code).
|
||||||
|
```
|
||||||
|
./node --mode coord --cfg cfg.buidler.toml discard --block 8061330
|
||||||
|
```
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ SendBatchBlocksMarginCheck = 1
|
|||||||
ProofServerPollInterval = "1s"
|
ProofServerPollInterval = "1s"
|
||||||
ForgeRetryInterval = "500ms"
|
ForgeRetryInterval = "500ms"
|
||||||
SyncRetryInterval = "1s"
|
SyncRetryInterval = "1s"
|
||||||
|
ForgeDelay = "10s"
|
||||||
|
ForgeNoTxsDelay = "0s"
|
||||||
|
|
||||||
[Coordinator.FeeAccount]
|
[Coordinator.FeeAccount]
|
||||||
Address = "0x56232B1c5B10038125Bc7345664B4AFD745bcF8E"
|
Address = "0x56232B1c5B10038125Bc7345664B4AFD745bcF8E"
|
||||||
@@ -83,16 +85,13 @@ MaxTx = 512
|
|||||||
NLevels = 32
|
NLevels = 32
|
||||||
|
|
||||||
[Coordinator.EthClient]
|
[Coordinator.EthClient]
|
||||||
ReceiptTimeout = "60s"
|
|
||||||
ReceiptLoopInterval = "500ms"
|
|
||||||
CheckLoopInterval = "500ms"
|
CheckLoopInterval = "500ms"
|
||||||
Attempts = 4
|
Attempts = 4
|
||||||
AttemptsDelay = "500ms"
|
AttemptsDelay = "500ms"
|
||||||
TxResendTimeout = "2m"
|
TxResendTimeout = "2m"
|
||||||
NoReuseNonce = false
|
NoReuseNonce = false
|
||||||
CallGasLimit = 300000
|
|
||||||
GasPriceDiv = 100
|
|
||||||
MaxGasPrice = "5000000000"
|
MaxGasPrice = "5000000000"
|
||||||
|
GasPriceIncPerc = 10
|
||||||
|
|
||||||
[Coordinator.EthClient.Keystore]
|
[Coordinator.EthClient.Keystore]
|
||||||
Path = "/tmp/iden3-test/hermez/ethkeystore"
|
Path = "/tmp/iden3-test/hermez/ethkeystore"
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/hermeznetwork/hermez-node/config"
|
"github.com/hermeznetwork/hermez-node/config"
|
||||||
dbUtils "github.com/hermeznetwork/hermez-node/db"
|
dbUtils "github.com/hermeznetwork/hermez-node/db"
|
||||||
|
"github.com/hermeznetwork/hermez-node/db/historydb"
|
||||||
|
"github.com/hermeznetwork/hermez-node/db/l2db"
|
||||||
"github.com/hermeznetwork/hermez-node/log"
|
"github.com/hermeznetwork/hermez-node/log"
|
||||||
"github.com/hermeznetwork/hermez-node/node"
|
"github.com/hermeznetwork/hermez-node/node"
|
||||||
"github.com/hermeznetwork/tracerr"
|
"github.com/hermeznetwork/tracerr"
|
||||||
@@ -23,6 +25,7 @@ const (
|
|||||||
flagMode = "mode"
|
flagMode = "mode"
|
||||||
flagSK = "privatekey"
|
flagSK = "privatekey"
|
||||||
flagYes = "yes"
|
flagYes = "yes"
|
||||||
|
flagBlock = "block"
|
||||||
modeSync = "sync"
|
modeSync = "sync"
|
||||||
modeCoord = "coord"
|
modeCoord = "coord"
|
||||||
)
|
)
|
||||||
@@ -139,6 +142,47 @@ func cmdRun(c *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cmdDiscard(c *cli.Context) error {
|
||||||
|
_cfg, err := parseCli(c)
|
||||||
|
if err != nil {
|
||||||
|
return tracerr.Wrap(fmt.Errorf("error parsing flags and config: %w", err))
|
||||||
|
}
|
||||||
|
cfg := _cfg.node
|
||||||
|
blockNum := c.Int64(flagBlock)
|
||||||
|
log.Infof("Discarding all blocks up to block %v...", blockNum)
|
||||||
|
|
||||||
|
db, err := dbUtils.InitSQLDB(
|
||||||
|
cfg.PostgreSQL.Port,
|
||||||
|
cfg.PostgreSQL.Host,
|
||||||
|
cfg.PostgreSQL.User,
|
||||||
|
cfg.PostgreSQL.Password,
|
||||||
|
cfg.PostgreSQL.Name,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return tracerr.Wrap(fmt.Errorf("dbUtils.InitSQLDB: %w", err))
|
||||||
|
}
|
||||||
|
historyDB := historydb.NewHistoryDB(db, nil)
|
||||||
|
if err := historyDB.Reorg(blockNum); err != nil {
|
||||||
|
return tracerr.Wrap(fmt.Errorf("historyDB.Reorg: %w", err))
|
||||||
|
}
|
||||||
|
batchNum, err := historyDB.GetLastBatchNum()
|
||||||
|
if err != nil {
|
||||||
|
return tracerr.Wrap(fmt.Errorf("historyDB.GetLastBatchNum: %w", err))
|
||||||
|
}
|
||||||
|
l2DB := l2db.NewL2DB(
|
||||||
|
db,
|
||||||
|
cfg.Coordinator.L2DB.SafetyPeriod,
|
||||||
|
cfg.Coordinator.L2DB.MaxTxs,
|
||||||
|
cfg.Coordinator.L2DB.TTL.Duration,
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
if err := l2DB.Reorg(batchNum); err != nil {
|
||||||
|
return tracerr.Wrap(fmt.Errorf("l2DB.Reorg: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Config is the configuration of the hermez node execution
|
// Config is the configuration of the hermez node execution
|
||||||
type Config struct {
|
type Config struct {
|
||||||
mode node.Mode
|
mode node.Mode
|
||||||
@@ -239,6 +283,18 @@ func main() {
|
|||||||
Usage: "Run the hermez-node in the indicated mode",
|
Usage: "Run the hermez-node in the indicated mode",
|
||||||
Action: cmdRun,
|
Action: cmdRun,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "discard",
|
||||||
|
Aliases: []string{},
|
||||||
|
Usage: "Discard blocks up to a specified block number",
|
||||||
|
Action: cmdDiscard,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.Int64Flag{
|
||||||
|
Name: flagBlock,
|
||||||
|
Usage: "last block number to keep",
|
||||||
|
Required: false,
|
||||||
|
}},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := app.Run(os.Args)
|
err := app.Run(os.Args)
|
||||||
|
|||||||
Reference in New Issue
Block a user