Files
hermez-node/test/til
Eduard S 8f1cf2f145 Update coordinator, call all api update functions
- Common:
	- Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition
- API:
	- Add UpdateNetworkInfoBlock to update just block information, to be
	  used when the node is not yet synchronized
- Node:
	- Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with
	  configurable time intervals
- Synchronizer:
	- When mapping events by TxHash, use an array to support the possibility
	  of multiple calls of the same function happening in the same
	  transaction (for example, a smart contract in a single transaction
	  could call withdraw with delay twice, which would generate 2 withdraw
	  events, and 2 deposit events).
	- In Stats, keep entire LastBlock instead of just the blockNum
	- In Stats, add lastL1BatchBlock
	- Test Stats and SCVars
- Coordinator:
	- Enable writing the BatchInfo in every step of the pipeline to disk
	  (with JSON text files) for debugging purposes.
	- Move the Pipeline functionality from the Coordinator to its own struct
	  (Pipeline)
	- Implement shouldL1lL2Batch
	- In TxManager, implement logic to perform several attempts when doing
	  ethereum node RPC calls before considering the error. (Both for calls
	  to forgeBatch and transaction receipt)
	- In TxManager, reorganize the flow and note the specific points in
	  which actions are made when err != nil
- HistoryDB:
	- Implement GetLastL1BatchBlockNum: returns the blockNum of the latest
	  forged l1Batch, to help the coordinator decide when to forge an
	  L1Batch.
- EthereumClient and test.Client:
	- Update EthBlockByNumber to return the last block when the passed
	  number is -1.
2020-11-26 18:06:30 +01:00
..
2020-11-17 16:33:29 +01:00
2020-11-03 11:26:23 +01:00

Til (Test instructions language)

Language to define sets of instructions to simulate Hermez transactions (L1 & L2) with real data.

Syntax

Global

  • Set type definition
    • Blockchain: generate the transactions that would come from the Hermez smart contract on the blockchain.
    Type: Blockchain
    
    • PoolL2: generate the transactions that would come from the Pool of L2Txs
    Type: PoolL2
    

Blockchain set of instructions

Available instructions:

Type: Blockchain

// add the TokenID:
AddToken(1)

// deposit of TokenID=1, on the account of tokenID=1 for the user A, of an
// amount of 50 units
CreateAccountDeposit(1) A: 50

// create the account of TokenID=1 for the user B, deposit of TokenID=1, on the
// account of tokenID=1 for the user B, of an amount of 40 units and atomically
// transfer 10 units to account of tokenID=1 for the user A
CreateAccountDepositTransfer(1) B-A: 40, 10

// transaction generated by the Coordinator, create account for user User0 for
// the TokenID=2, with a deposit of 0
CreateAccountCoordinator(2) User0


// deposit of TokenID=1, at the account A, of 6 units
Deposit(1) A: 6

// deposit of TokenID=1, on the account of tokenID=1 for the user B, of an
// amount of 6 units and atomically transfer 10 units to account of tokenID=1 for
// the user A
DepositTransfer(1) B-A: 6, 4

// transfer of TokenID=1, from the account A to B (for that token), of 6 units,
// paying a fee of 3. Transaction will be a L2Tx
Transfer(1) A-B: 6 (3)

// exit of TokenID=1, from the account A (for that token), of 5 units, paying a
// fee of 1. Transaction will be a L2Tx
Exit(1) A: 5 (1)

// force-transfer of TokenID=1, from the account A to B (for that token), of 6
// units. Transaction will be L1UserTx of ForceTransfer type
ForceTransfer(1) A-B: 6

// force-exit of TokenID=1, from the account A (for that token), of 5 units.
// Transaction will be L1UserTx of ForceExit type
ForceExit(1) A: 5

// advance one batch, forging without L1UserTxs, only can contain L2Txs and
// L1CoordinatorTxs
> batch

// advance one batch, forging with L1UserTxs (and L2Txs and L1CoordinatorTxs)
> batchL1

// advance an ethereum block
> block

PoolL2 set of instructions

Available instructions:

Type: PoolL2

// transfer of TokenID=1, from the account A to B (for that token), of 6 units,
// paying a fee of 4
PoolTransfer(1) A-B: 6 (4)

// exit of TokenID=1, from the account A (for that token), of 3 units, paying a
// fee of 1
PoolExit(1) A: 3 (1)

Usage

// create a new til.Context
tc := til.NewContext(eth.RollupConstMaxL1UserTx)

// generate Blockchain blocks data from the common.SetBlockcahin0 instructions set
blocks, err = tc.GenerateBlocks(common.SetBlockchainMinimumFlow0)
assert.Nil(t, err)

// generate PoolL2 transactions data from the common.SetPool0 instructions set
poolL2Txs, err = tc.GeneratePoolL2Txs(common.SetPoolL2MinimumFlow0)
assert.Nil(t, err)

Where blocks will contain:

// BatchData contains the information of a Batch
type BatchData struct {
    L1CoordinatorTxs     []common.L1Tx
    L2Txs                []common.L2Tx
    CreatedAccounts []common.Account
}

// BlockData contains the information of a Block
type BlockData struct {
    L1UserTxs        []common.L1Tx
    Batches          []BatchData
    RegisteredTokens []common.Token
}