Commit Graph

272 Commits

Author SHA1 Message Date
arnaucube
ca5870e3ba Update ExitProofs-Siblings padding 2020-12-30 10:44:34 +01:00
Eduard S
88f924e9dd Merge pull request #435 from hermeznetwork/feature/addrs-in-exit-endpoints
Include addrs in exit responses
2020-12-29 18:01:46 +01:00
Arnau B
6cd292b937 Include addrs in exit responses 2020-12-29 17:35:20 +01:00
Eduard S
8c6dc6e3f8 Merge pull request #433 from hermeznetwork/feature/kvdb
Abstract KVDB from StateDB
2020-12-29 17:21:01 +01:00
arnaucube
68bfbff269 Abstract KVDB from StateDB
- KVDB contains the Checkpoint & Resets system
- StateDB uses KVDB and adds all the StateDB related methods
2020-12-29 16:48:01 +01:00
Eduard S
890b94a41a Merge pull request #428 from hermeznetwork/fix/api-next-forgers
Fix next forgers api response
2020-12-29 15:32:02 +01:00
Arnau B
6058d3c41a Fix next forgers api response 2020-12-29 15:17:55 +01:00
Eduard S
02c2ee155a Fix item_id order in forged l1UserTxs
Also, make sure that all SQL queries that return slices are sorted
2020-12-29 12:28:53 +01:00
arnaucube
0cf1ed217b Abstract TxProcessor from StateDB
- Abstract TxProcessor from StateDB
- Upgrade to last version of go-merkletree for the key-value DB usage
2020-12-29 11:14:38 +01:00
arnaucube
cf199fd832 Fix ZKI NTx for MaxTx
On the Circuits uses the name `nTx` (and on the tests `maxTx`), but
Contracts `maxTx`. On Go we had both variables, but really only used
one, now at Go we use `MaxTx` to refer to the maximum number of
transactions.
2020-12-28 11:26:47 +01:00
arnau
cbcd387f98 Merge pull request #423 from hermeznetwork/feature/integration27
Delete old checkpoints in stateDB automatically & Don't log errors when context done
2020-12-28 11:15:00 +01:00
Eduard S
a0c8ace38d Add missing tracerr.Wrap 2020-12-24 13:39:27 +01:00
Eduard S
2205fcadbc Delete old checkpoints in stateDB automatically
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.
2020-12-24 13:35:47 +01:00
arnaucube
8615a462ab Update AccountCreationAuth & fix auth.HashToSign
- Fix AccountCreationAuth.HashToSign (was using `[]byte("0x...")`, which
uses the bytes of the string. Now uses the bytearray of the compressed
BJJ public key (compatible with js implementation))
- Update AccountCreationAuth to last specification (add to hash
parameters ChainID & HermezAddress)
- Add missing test to AccountCreationAuth
2020-12-24 10:41:35 +01:00
Eduard S
8267d007c9 Sync ForgerCommitment and use it in coord
Previously the coordinator was erroneously using Slot.BatchesLen to determine
when anyone can forge.  The correct behaviour is implmenented with the boolean
flag `ForgerCommitment`, that is set to true only when there's a batch before
the deadline within a slot.

Delete Slot.BatchesLen, and the synchronization code of this value from the
Synchronizer, as this is not needed
2020-12-23 17:06:20 +01:00
arnaucube
150597c282 Parametrize ChainID 2020-12-23 15:23:48 +01:00
Eduard S
adc044001f Merge pull request #412 from hermeznetwork/fix/sdb-nonce
Fix StateDB & Til Nonce increment
2020-12-23 12:47:40 +01:00
arnaucube
eea44b3990 Fix StateDB & Til Nonce increment 2020-12-23 12:32:41 +01:00
Eduard S
fb48ca4e58 Merge pull request #411 from hermeznetwork/feature/forged-txs-in-batchesapi
Add forged txs in batch endpoints response
2020-12-23 12:07:45 +01:00
arnaucube
982a423bf3 TxSelector update txs processing logic 2020-12-23 11:36:41 +01:00
Arnau B
6e7f860d61 Add forged txs in batch endpoints response 2020-12-23 11:26:23 +01:00
arnau
3cf615a769 Merge pull request #406 from hermeznetwork/feature/implforgebatchargs
Implement Pipeline.prepareForgeBatchArgs()
2020-12-23 11:22:28 +01:00
Eduard S
8d5b375625 Merge pull request #407 from hermeznetwork/fix/api-coordinator
Add bootCoord to coord table, get coord by forgerAddr
2020-12-23 11:10:23 +01:00
arnaucube
2583d35adf Update ZKInputs for empty batches
- Add TestZKInputsEmpty circom test vectors
- Fix ZKInputsHash OldLastIdx bytearray
2020-12-23 11:09:43 +01:00
Arnau B
bc5fa92898 Add bootCoord to coord table, get coord by forgerAddr 2020-12-23 11:03:21 +01:00
Eduard S
6a990376b4 Implement Pipeline.prepareForgeBatchArgs()
- 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.
2020-12-22 17:27:34 +01:00
Eduard S
a8ac35059a Test purger, fix some nonces
- Test all the purger functions
- Fix nonces set by til (previously til started with nonce 1 for pool l2txs,
  but the correct implementation is to start with nonce 0)
- Rename L2DB.CheckNonces to L2DB.invalidateOldNoncesQuery
- Rename L2DB.checkNoncesQuery to L2DB.InvalidateOldNonces

Related https://github.com/hermeznetwork/hermez-node/issues/392 (Fix checkNoncesQuery)
Resolve https://github.com/hermeznetwork/hermez-node/issues/396
2020-12-22 12:00:12 +01:00
arnaucube
4b10549822 mv of babyjub.PublicKey to babyjub.PublicKeyComp
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
2020-12-22 11:29:47 +01:00
laisolizq
bc29222341 Fix historyDB GetBestBidCoordinator 2020-12-18 17:47:41 +01:00
arnaucube
0bcf57603c Effective amounts add missing checks 2020-12-17 17:51:23 +01:00
Eduard S
8a59296cb8 Fix order of L1UserTxs
When the synchronizer queries the unforged L1UserTxs, sort them by position

Swap the order of calls setL1UserTxEffectiveAmounts and addBatch in
AddBlockSCData because otherwise, for reasons I dont understand, the item_id of
the txs doesn't follow the position of the txs.
2020-12-17 15:48:01 +01:00
Eduard S
12fba96eee Merge pull request #366 from hermeznetwork/fix/api-exit-response
Fix format of the MTP for exit endpoint
2020-12-17 11:02:31 +01:00
arnau
f58cadb34e Merge pull request #362 from hermeznetwork/feature/updatetxs
Update txs constructors and helpers
2020-12-17 10:53:12 +01:00
Arnau B
8083e4fec3 Fix format of the MTP for exit endpoint 2020-12-16 20:09:17 +01:00
arnau
6dd766be4d Merge pull request #359 from hermeznetwork/feature/integration25
Extend Coordinator tests
2020-12-16 18:07:44 +01:00
Eduard S
7a30294688 Update txs constructors and helpers
For each tx, move the logic of setting the Type and TxID to separate functions,
so that they can be called when necessary.

In synchronizer, set all the required fields using the `SetID` and `SetType`
for l2txs when needed.  This is necessary because the `ProcessTxs()` works with
`common.PoolL2Tx`, which misses some fields from `common.L2Tx`, and because
`ProcessTxs()` needs the Type to be set, but at the same time `ProcessTxs()`
sets the Nonce, which is required for the `TxID`.
2020-12-16 15:25:55 +01:00
Eduard S
6a9b5ce420 Extend Coordinator tests 2020-12-16 13:13:40 +01:00
arnaucube
0955016049 Update StateDB computeEffectiveAmounts
For the case of tx.EthAddr!=tx.FromIdx.EthAddr
2020-12-16 11:55:53 +01:00
Eduard S
8e1bfd150d Merge pull request #352 from hermeznetwork/fix/historydb-norows
Fix queries when no rows
2020-12-15 16:29:03 +01:00
Arnau B
c7b7a85b85 Fix queries when no rows 2020-12-15 16:15:42 +01:00
Eduard S
d15721d28a Merge pull request #350 from hermeznetwork/feature/zkinputs6
Update ZKInputs generation:
2020-12-15 15:44:31 +01:00
Eduard S
a7351992cd Make coordinator more responsive
- API:
	- Replace `emergencyModeStaringTime` by `emercengyModeStartingBlock`
- Synchronizer:
	- Track emergency mode starting block
- cli/node
	- Add working coordinator config
- coordinator:
	- Retry handler for synchronizer stats in case of error (instead of
	  waiting for the next block to try again)
	- On init, trigger an initial call to the handler for synced block
	  before waiting for the synchronizer, to force the coordinator to start
	  its logic even if there's no new block right after the node has been
	  started (very useful for running in testnet where the frequency of
	  blocks is variable)
	- Merge Msg for synced block and updated vars into one: `MsgSyncBlock`.
2020-12-15 15:15:25 +01:00
arnaucube
593a477e6c ZKInputs generation ISFinalAccFee update
- Update IntermediateState FinalAccFee values to fit in the Circom circuit expected inputs
- Add ZKInputs generation test with transactions generated by Til
(TestZKInputs6)
- BatchBuilder: remove redundant MakeCheckpoint call
2020-12-15 11:49:09 +01:00
arnaucube
a4584499a4 StateDB Exit & ForceExit correct processing & ZKI
- Update tx processor of Exit & ForceExit types
- Update ZKInputs generation related to Exit transactions
- Add TestZKInputs5 which adds tests generation of ZKInputs compatible
with Circom circuits including Exit (L2) & ForceExit (L1) transaction types
- Add StateDB test to check max DepositAmount case
2020-12-11 12:39:05 +01:00
Eduard S
20b8d0561f Update synchronizer and DB with last contracts updates
- API
	- When updating network info, handle cases where no batches exists and
	  where no forgers exists
- cli/node
	- Update `cfg.buidler.toml` config file to a working version
- common
	- Add new smart contract structs and extend some existing ones to
	  reflect updates regarding events from the smart contracts
- SQL
	- Add new tables and extend existing ones to reflect updates regarding
	  events from the smart contracts
- db/historydb
	- Add functions to insert new smart contract events data
	- Fix unclosed rows that led to inconsistent sql driver state (replace
	  NamedQuery by NamedExec).  This fixes the error:
	  `pq: unexpected Parse response 'C'`
- db/l2db
	- Close rows after usage
- eth
	- In Rollup event, introduce a new UpdateBucketsParameter when there's a
	  SafeMode event, with `SafeMode = true`
- synchronizer
	- synchronize new events
	- avoid calling `auction.CanForge` before the genesisBlock to avoid
	  getting a revert.
2020-12-10 17:45:17 +01:00
arnaucube
e7c8328df1 Fix process L1Tx for correct ZKInputs generation
- StateDB fix process txs of type CreateAccountDepositTransfer & DepositTransfer
- Add TestZKInputs3 & TestZKInputs4 which:
    - have a compatible check in js version to check Circom circuits
compatibility
    - adds test of tx type of CreateAccountDepositTransfer &
DepositTransfer
2020-12-10 12:59:01 +01:00
arnaucube
9d0b278d50 Update missing LoadAmount to DepositAmount
Related to 445f26ec9f
2020-12-09 18:34:01 +01:00
Eduard S
d5c753030a Merge pull request #338 from hermeznetwork/feature/api-amounts
Add amount success and load amount success
2020-12-09 17:20:21 +01:00
Arnau B
e1d34e3796 Add amount success and load amount success 2020-12-09 16:39:18 +01:00
laisolizq
d5f579aec5 Merge pull request #336 from hermeznetwork/fix/api1
Fix/api1
2020-12-09 16:08:01 +01:00