Update missing parts, improve til, and more

- Node
	- Updated configuration to initialize the interface to all the smart
	  contracts
- Common
	- Moved BlockData and BatchData types to common so that they can be
	  shared among: historydb, til and synchronizer
	- Remove hash.go (it was never used)
	- Remove slot.go (it was never used)
	- Remove smartcontractparams.go (it was never used, and appropriate
	  structs are defined in `eth/`)
	- Comment state / status method until requirements of this method are
	  properly defined, and move it to Synchronizer
- Synchronizer
	- Simplify `Sync` routine to only sync one block per call, and return
	  useful information.
	- Use BlockData and BatchData from common
	- Check that events belong to the expected block hash
	- In L1Batch, query L1UserTxs from HistoryDB
	- Fill ERC20 token information
	- Test AddTokens with test.Client
- HistryDB
	- Use BlockData and BatchData from common
	- Add `GetAllTokens` method
	- Uncomment and update GetL1UserTxs (with corresponding tests)
- Til
	- Rename all instances of RegisterToken to AddToken (to follow the smart
	  contract implementation naming)
	- Use BlockData and BatchData from common
		- Move testL1CoordinatorTxs and testL2Txs to a separate struct
		  from BatchData in Context
	- Start Context with BatchNum = 1 (which the protocol defines to be the
	  first batchNum)
	- In every Batch, set StateRoot and ExitRoot to a non-nil big.Int
	  (zero).
	- In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not
	  used, set it to 0; so that no *big.Int is nil.
	- In L1UserTx, don't set BatchNum, because when L1UserTxs are created
	  and obtained by the synchronizer, the BatchNum is not known yet (it's
	  a synchronizer job to set it)
	- In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
This commit is contained in:
Eduard S
2020-10-09 12:54:16 +02:00
parent 24bca9e3b0
commit 827e917fa0
23 changed files with 739 additions and 547 deletions

View File

@@ -16,11 +16,11 @@ type Batch struct {
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum block in which the batch is forged
ForgerAddr ethCommon.Address `meddler:"forger_addr"` // TODO: Should this be retrieved via slot reference?
CollectedFees map[TokenID]*big.Int `meddler:"fees_collected,json"`
StateRoot Hash `meddler:"state_root"`
StateRoot *big.Int `meddler:"state_root,bigint"`
NumAccounts int `meddler:"num_accounts"`
ExitRoot Hash `meddler:"exit_root"`
ExitRoot *big.Int `meddler:"exit_root,bigint"`
ForgeL1TxsNum *int64 `meddler:"forge_l1_txs_num"` // optional, Only when the batch forges L1 txs. Identifier that corresponds to the group of L1 txs forged in the current batch.
SlotNum SlotNum `meddler:"slot_num"` // Slot in which the batch is forged
SlotNum int64 `meddler:"slot_num"` // Slot in which the batch is forged
TotalFeesUSD *float64 `meddler:"total_fees_usd"`
}

View File

@@ -8,7 +8,7 @@ import (
// Bid is a struct that represents one bid in the PoH
type Bid struct {
SlotNum SlotNum `meddler:"slot_num"`
SlotNum int64 `meddler:"slot_num"`
BidValue *big.Int `meddler:"bid_value,bigint"`
EthBlockNum int64 `meddler:"eth_block_num"`
Bidder ethCommon.Address `meddler:"bidder_addr"` // Coordinator reference

View File

@@ -13,3 +13,46 @@ type Block struct {
Hash ethCommon.Hash `meddler:"hash"`
ParentHash ethCommon.Hash `meddler:"-"`
}
// BlockData contains the information of a Block
type BlockData struct {
Block Block
// Rollup
// L1UserTxs that were submitted in the block
L1UserTxs []L1Tx
Batches []BatchData
AddedTokens []Token
RollupVars *RollupVars
// Auction
Bids []Bid
Coordinators []Coordinator
AuctionVars *AuctionVars
WithdrawDelayerVars *WithdrawDelayerVars
// TODO: enable when common.WithdrawalDelayerVars is Merged from Synchronizer PR
// WithdrawalDelayerVars *common.WithdrawalDelayerVars
}
// BatchData contains the information of a Batch
type BatchData struct {
// L1UserTxs that were forged in the batch
L1Batch bool // TODO: Remove once Batch.ForgeL1TxsNum is a pointer
// L1UserTxs []common.L1Tx
L1CoordinatorTxs []L1Tx
L2Txs []L2Tx
CreatedAccounts []Account
ExitTree []ExitInfo
Batch Batch
}
// NewBatchData creates an empty BatchData with the slices initialized.
func NewBatchData() *BatchData {
return &BatchData{
L1Batch: false,
// L1UserTxs: make([]common.L1Tx, 0),
L1CoordinatorTxs: make([]L1Tx, 0),
L2Txs: make([]L2Tx, 0),
CreatedAccounts: make([]Account, 0),
ExitTree: make([]ExitInfo, 0),
Batch: Batch{},
}
}

View File

@@ -1,4 +0,0 @@
package common
// Hash is the used hash for Hermez network
type Hash []byte

View File

@@ -1,28 +0,0 @@
package common
import (
"math/big"
)
// Slot represents a slot of the Hermez network
// WARNING: this is strongly based on the previous implementation, once the new spec is done, this may change a lot.
type Slot struct {
SlotNum SlotNum
StartingBlock uint64 // Ethereum block in which the slot starts
Forger Coordinator // Current Operaror winner information
}
// SlotMinPrice is the policy of minimum prices for strt bidding in the slots
type SlotMinPrice struct {
EthBlockNum uint64 // Etherum block in which the min price was updated
MinPrices [6]big.Int
}
// GetMinPrice returns the minimum bid to enter the auction for a specific slot
func (smp *SlotMinPrice) GetMinPrice(slotNum SlotNum) *big.Int {
// TODO
return nil
}
// SlotNum identifies a slot
type SlotNum uint32

View File

@@ -1,21 +0,0 @@
package common
import (
"math/big"
ethCommon "github.com/ethereum/go-ethereum/common"
)
// SmartContractParameters describes the constant values of the parameters of the Hermez smart contracts
// WARNING: not stable at all
type SmartContractParameters struct {
SlotDuration uint64 // number of ethereum blocks in a slot
Slot0BlockNum uint64 // ethereum block number of the first slot (slot 0)
MaxL1UserTxs uint64 // maximum number of L1UserTxs that can be queued for a single batch
FreeCoordinatorWait uint64 // if the winning coordinator doesn't forge during this number of blocks, anyone can forge
ContractAddr ethCommon.Address // Ethereum address of the rollup smart contract
NLevels uint16 // Heigth of the SMT. This will determine the maximum number of accounts that can coexist in the Hermez network by 2^nLevels
MaxTxs uint16 // Max amount of txs that can be added in a batch, either L1 or L2
FeeL1Tx *big.Int // amount of eth (in wei) that has to be paid to do a L1 tx
FeeDeposit *big.Int // amount of eth (in wei) that has to be paid to do a deposit
}

View File

@@ -1,16 +0,0 @@
package common
import (
"time"
)
// SyncronizerState describes the synchronization progress of the smart contracts
type SyncronizerState struct {
LastUpdate time.Time // last time this information was updated
CurrentBatchNum BatchNum // Last batch that was forged on the blockchain
CurrentBlockNum uint64 // Last block that was mined on Ethereum
CurrentToForgeL1TxsNum uint32
LastSyncedBatchNum BatchNum // last batch synchronized by the coordinator
LastSyncedBlockNum uint64 // last Ethereum block synchronized by the coordinator
LastSyncedToForgeL1TxsNum uint32
}

View File

@@ -1,12 +0,0 @@
package common
import ethCommon "github.com/ethereum/go-ethereum/common"
// SyncStatus is returned by the Status method of the Synchronizer
type SyncStatus struct {
CurrentBlock int64
CurrentBatch BatchNum
CurrentForgerAddr ethCommon.Address
NextForgerAddr ethCommon.Address
Synchronized bool
}