Previous to this commit, there were cases where being
len(nonForgableL2Txs)>maxL2Txs and nonForgableL2Txs have bigger fee than
forgableL2Txs, the forgableTxs where never forged, neither the
nonForgableTxs. Now, the TxSelector first forges the forgableTxs (which
are forgable for the initial state of the accounts (balances & nonces),
and then the nonForgableL2Txs, which may be unblocked once the forgable
ones have been processed.
Updated:
batchbuilder
common
coordinator
db/statedb
eth
log
node
priceupdater
prover
synchronizer
test/*
txprocessor
txselector
Pending (once
https://github.com/hermeznetwork/hermez-node/tree/feature/serveapicli is
merged to master):
Update golangci-lint version to v1.37.1
api
apitypes
cli
config
db/historydb
db/l2db
- cli / node
- Update handler of SIGINT so that after 3 SIGINTs, the process terminates
unconditionally
- coordinator
- Store stats without pointer
- In all functions that send a variable via channel, check for context done
to avoid deadlock (due to no process reading from the channel, which has
no queue) when the node is stopped.
- Abstract `canForge` so that it can be used outside of the `Coordinator`
- In `canForge` check the blockNumber in current and next slot.
- Update tests due to smart contract changes in slot handling, and minimum
bid defaults
- TxManager
- Add consts, vars and stats to allow evaluating `canForge`
- Add `canForge` method (not used yet)
- Store batch and nonces status (last success and last pending)
- Track nonces internally instead of relying on the ethereum node (this
is required to work with ganache when there are pending txs)
- Handle the (common) case of the receipt not being found after the tx
is sent.
- Don't start the main loop until we get an initial messae fo the stats
and vars (so that in the loop the stats and vars are set to
synchronizer values)
- When a tx fails, check and discard all the failed transactions before
sending the message to stop the pipeline. This will avoid sending
consecutive messages of stop the pipeline when multiple txs are
detected to be failed consecutively. Also, future txs of the same
pipeline after a discarded txs are discarded, and their nonces reused.
- Robust handling of nonces:
- If geth returns nonce is too low, increase it
- If geth returns nonce too hight, decrease it
- If geth returns underpriced, increase gas price
- If geth returns replace underpriced, increase gas price
- Add support for resending transactions after a timeout
- Store `BatchInfos` in a queue
- Pipeline
- When an error is found, stop forging batches and send a message to the
coordinator to stop the pipeline with information of the failed batch
number so that in a restart, non-failed batches are not repated.
- When doing a reset of the stateDB, if possible reset from the local
checkpoint instead of resetting from the synchronizer. This allows
resetting from a batch that is valid but not yet sent / synced.
- Every time a pipeline is started, assign it a number from a counter. This
allows the TxManager to ignore batches from stopped pipelines, via a
message sent by the coordinator.
- Avoid forging when we haven't reached the rollup genesis block number.
- Add config parameter `StartSlotBlocksDelay`: StartSlotBlocksDelay is the
number of blocks of delay to wait before starting the pipeline when we
reach a slot in which we can forge.
- When detecting a reorg, only reset the pipeline if the batch from which
the pipeline started changed and wasn't sent by us.
- Add config parameter `ScheduleBatchBlocksAheadCheck`:
ScheduleBatchBlocksAheadCheck is the number of blocks ahead in which the
forger address is checked to be allowed to forge (apart from checking the
next block), used to decide when to stop scheduling new batches (by
stopping the pipeline). For example, if we are at block 10 and
ScheduleBatchBlocksAheadCheck is 5, eventhough at block 11 we canForge,
the pipeline will be stopped if we can't forge at block 15. This value
should be the expected number of blocks it takes between scheduling a
batch and having it mined.
- Add config parameter `SendBatchBlocksMarginCheck`:
SendBatchBlocksMarginCheck is the number of margin blocks ahead in which
the coordinator is also checked to be allowed to forge, apart from the
next block; used to decide when to stop sending batches to the smart
contract. For example, if we are at block 10 and
SendBatchBlocksMarginCheck is 5, eventhough at block 11 we canForge, the
batch will be discarded if we can't forge at block 15.
- Add config parameter `TxResendTimeout`: TxResendTimeout is the timeout
after which a non-mined ethereum transaction will be resent (reusing the
nonce) with a newly calculated gas price
- Add config parameter `MaxGasPrice`: MaxGasPrice is the maximum gas price
allowed for ethereum transactions
- Add config parameter `NoReuseNonce`: NoReuseNonce disables reusing nonces
of pending transactions for new replacement transactions. This is useful
for testing with Ganache.
- Extend BatchInfo with more useful information for debugging
- eth / ethereum client
- Add necessary methods to create the auth object for transactions manually
so that we can set the nonce, gas price, gas limit, etc manually
- Update `RollupForgeBatch` to take an auth object as input (so that the
coordinator can set parameters manually)
- synchronizer
- In stats, add `NextSlot`
- In stats, store full last batch instead of just last batch number
- Instead of calculating a nextSlot from scratch every time, update the
current struct (only updating the forger info if we are Synced)
- Afer every processed batch, check that the calculated StateDB MTRoot
matches the StateRoot found in the forgeBatch event.
- KVDB/StateDB
- Pass config parameters in a Config type instead of using many
arguments in constructor.
- Add new parameter `NoLast` which disables having an opened DB with a
checkpoint to the last batchNum for thread-safe reads. Last will be
disabled in the StateDB used by the TxSelector and BatchBuilder.
- Add new parameter `NoGapsCheck` which skips checking gaps in the list
of checkpoints and returning errors if there are gaps. Gaps check
will be disabled in the StateDB used by the TxSelector and
BatchBuilder, because we expect to have gaps when there are multiple
coordinators forging (slots not forged by our coordinator will leave
gaps).
PoolL2Tx.Info contains information about the status & State of the
transaction. As for example, if the Tx has not been selected in the last
batch due not enough Balance at the Sender account, this reason would
appear at this parameter.
This will help the client (wallet, batchexplorer, etc) to reason why a
L2Tx is not selected in the forged batches.
- TxSelector
- Add check enough funds on sender at TxSelector and don't
include the tx in the selection
- TxProcessor
- Add checks that the balance when substracted the
amount/amount+fee never goes below 0
fix#502
- Upgrade go-merkletree version to include the last changes of Pebble
that fixes the cgo issues (which should fix#453), from:
c2b05f12d7
- TxSelector
- Remove parameter batchNum for GetL2TxSelection & GetL1L2TxSelection
- Add checks of ToBJJ & ToEthAddr when ToIdx>255
- Avoid getting the sender account twice to get the TokenID of a l2tx
- Add test to check that selected L2Txs are sorted by Nonce
- Discard L2Tx that return error at ProcessL2Txs
- executed `go mod tidy`
- Add missing Fees to CoordAccounts after processing PoolL2Txs
- Add Nonces checks for L2Txs (txs with incorrect nonces not included
in the selection)
- Add missing MakeCheckpoint() at the LocalAccountsDB once the
selection is done
- Add TxSelector test of full flow using Til.SetBlockchainMinimumFlow0
checking balances & parameters
- StateDB
- Update GetIdxByEthAddrBJJ to return ErrToIdxNotFound when idx not found, so can be checked at upper levels
- TxSelector
- rm CoordIdxsDB that is no longer needed (also related methods)
- add `getCoordIdx` method to get the Coordinator Idx for a given TokenID
- Update coordinator account creation related to new TokenIDs from L2Txs
- Reorganize GetL1L2TxSelection
- return CoordIdxs used in the selection
- Update go-merkletree version which avoids marshaling Siblings to json
with 'null' value in case of empty array
Introduce a constructor parameter for the StateDB called `keep`, which tells
how many checkpoints to keep. When doing a new checkpoint, if the number of
existing checkpoints exeeds `keep`, the oldest ones will be deleted.
Add return of AccountCreationAuths at the TxSelector, which is an array
of bytearrays with the signatures of the AccountCreationAuthorization of
the accounts of the users created by the Coordinator with
L1CoordinatorTxs of those accounts that does not exist yet but there is
a transactions to them and the authorization of account creation exists.
- Implement Pipeline.prepareForgeBatchArgs()
- Add a minimal stress test for the coordinator (that also runs the
synchronizer)
- Update txprocessor.ProcessTxs() to return valid results for batches without
transactions
- Add the boilerplate for the corresponding test, leaving as TODO the
zkInput values
- Update prover client to use the same point format as proof server (projective)
- Update interface of TxSelector.GetCoordIdxs to also return the authorizations
to create accounts that go with the l1CoordinatorTxs.
Update usage of `*babyjub.PublicKey` to `babyjub.PublicKeyComp`
- when the key is not defined, internally is used `babyjub.EmptyBJJComp`, which is a `[32]byte` of zeroes of type `babyjub.PublicKeyComp`
- the API continues returning `nil` when the key is not defined
TxTypeToEthAddr & TxTypeToBJJ
- TxSelector
- Add SelectionConfig for each batch
- Add CoordIdxDB key-value where the CoordinatorIdxs are stored
- Separated method for filtering TxTypeToEthAddr & TxTypeToBJJ
- Common
- Add `IdxNonce` type used to track nonces in accounts to invalidate
l2txs in the pool
- Config
- Update coordinator config will all the new configuration parameters
used in the coordinator
- Coordinator
- Introduce the `Purger` to track how often to purge and do the job when
needed according to a configuration.
- Implement the methods to invalidate l2txs transactions due to l2txs
selection in batches. For now these functions are not used in favour
of the `Purger` methods, which check ALL the l2txs in the pool.
- Call Invalidation and Purging methods of the purger both when the
node is forging (in the pipeline when starting a new batch) and when
the node is not forging (in coordinator when being notified about a
new synced block)
- L2DB:
- Implement `GetPendingUniqueFromIdxs` to get all the unique idxs from
pending transactions (used to get their nonces and then invalidate
txs)
- Redo `CheckNonces` with a single SQL query and using `common.IdxNonce`
instead of `common.Account`
- StateDB:
- Expose GetIdx to check errors when invalidating pool txs
- Synchronizer:
- Test forged L1UserTxs processed by TxProcessor
- Improve checks of Effective values
- TxSelector:
- Expose the internal LocalStateDB in order to check account nonces in
the coordinator when not forging.
Add HashGlobalInputs for ZKInputs compatible with js & circom circuits version.
Compatible with hermeznetwork/commonjs at version: c6a1448db5
(c6a1448db5)
- Implement new TxID spec that distinguishes L1UserTx and L1CoordinatorTx
- Replace some type []*Foo by []Foo
- Fix HistoryDB & L2DB bug: in case of error, a rollback was applied and the returned error was nil
- Reorder inserts in historydb.NewHistoryDB() to follow foreign key dependencies
- Add initial synchronizer test with test.Client (for now, only tested l1UserTxs, blocks, addToken)
- Update L1UserTx event in test.Client
Add TxID calculation & New{Layer}Tx Type
New{Layer}Tx methods that compute the `TxID` & `TxType` values from the
transaction values:
- NewL1Tx
- NewL2Tx
- NewPoolL2Tx
Add TxID Scanner & Valuer for database/sql
HistoryDB & L2DB & API packages tests will need to be addapted to the
TestTransaction generation once is done.
- GetL2TxSelection & GetL1L2TxSelection integrated with dbs
- Create L1CoordinatorTx of type CreateAccountDeposit when a L2
requires it (and the AccountCreationAuth exists)