Add sync interface
Arnau B arnaubennassar5@gmail.com
Thu, 20 Aug 2020 16:17:14 +0200
6 files changed,
118 insertions(+),
16 deletions(-)
A
common/exittree.go
@@ -0,0 +1,12 @@
+package common + +import ( + "math/big" +) + +type ExitTreeLeaf struct { + AccountIdx Idx + MerkleProof []byte + Amount *big.Int + Nullifier *big.Int +}
M
common/l1tx.go
→
common/l1tx.go
@@ -32,8 +32,6 @@ TxID: tx.TxID,
FromIdx: tx.FromIdx, ToIdx: tx.ToIdx, Amount: tx.Amount, - Nonce: 0, - Fee: 0, Type: tx.Type, } }
A
common/scvars.go
@@ -0,0 +1,37 @@
+package common + +import ( + "math/big" + + eth "github.com/ethereum/go-ethereum/common" +) + +type RollupVars struct { + EthBlockNum uint64 + ForgeL1Timeout *big.Int + FeeL1UserTx *big.Int + FeeAddToken *big.Int + TokensHEZ eth.Address + Governance eth.Address +} + +type PoDVars struct { + EthBlockNum uint64 + SlotDeadline uint + CloseAuctionSlots uint + OpenAuctionSlots uint + Governance eth.Address + MinBidSlots MinBidSlots + Outbidding int + DonationAddress eth.Address + GovernanceAddress eth.Address + AllocationRatio AllocationRatio +} + +type MinBidSlots [6]uint + +type AllocationRatio struct { + Donation uint + Burn uint + Forger uint +}
M
db/historydb/historydb.go
→
db/historydb/historydb.go
@@ -40,7 +40,12 @@
return &HistoryDB{hdb}, nil } -// addBlocks insert blocks into the DB +// AddBlock insert a block into the DB +func (hdb *HistoryDB) AddBlock(blocks *common.Block) error { + return nil +} + +// addBlocks insert blocks into the DB. TODO: move method to test func (hdb *HistoryDB) addBlocks(blocks []common.Block) error { return db.BulkInsert( hdb.db,@@ -60,11 +65,36 @@ )
return blocks, err } -// reorg deletes all the information that was added into the DB after the lastValidBlock +// Reorg deletes all the information that was added into the DB after the lastValidBlock // WARNING: this is a draaft of the function, useful at the moment for tests -func (hdb *HistoryDB) reorg(lastValidBlock uint64) error { +func (hdb *HistoryDB) Reorg(lastValidBlock uint64) error { _, err := hdb.db.Exec("DELETE FROM block WHERE eth_block_num > $1;", lastValidBlock) return err +} + +// SyncRollup stores all the data that can be changed / added on a block in the Rollup SC +func (hdb *HistoryDB) SyncRollup( + blockNum uint64, + l1txs []common.L1Tx, + l2txs []common.L2Tx, + registeredAccounts []common.Account, + exitTree common.ExitTreeLeaf, + withdrawals common.ExitTreeLeaf, + registeredTokens []common.Token, + batch *common.Batch, + vars *common.RollupVars, +) error { + return nil +} + +// SyncPoD stores all the data that can be changed / added on a block in the PoD SC +func (hdb *HistoryDB) SyncPoD( + blockNum uint64, + bids []common.Bid, + coordinators []common.Coordinator, + vars *common.PoDVars, +) error { + return nil } // addBids insert Bids into the DB
M
db/historydb/historydb_test.go
→
db/historydb/historydb_test.go
@@ -44,7 +44,7 @@ var fromBlock, toBlock uint64
fromBlock = 1 toBlock = 5 // Delete peviously created rows (clean previous test execs) - assert.NoError(t, historyDB.reorg(fromBlock-1)) + assert.NoError(t, historyDB.Reorg(fromBlock-1)) // Generate fake blocks blocks := genBlocks(fromBlock, toBlock) // Insert blocks into DB@@ -95,11 +95,11 @@
// setTestBlocks WARNING: this will delete the blocks and recreate them func setTestBlocks(from, to uint64) { if from == 0 { - if err := historyDB.reorg(from); err != nil { + if err := historyDB.Reorg(from); err != nil { panic(err) } } else { - if err := historyDB.reorg(from - 1); err != nil { + if err := historyDB.Reorg(from - 1); err != nil { panic(err) } }
M
db/historydb/migrations/001_init.sql
→
db/historydb/migrations/001_init.sql
@@ -5,11 +5,6 @@ timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL,
hash BYTEA NOT NULL ); -CREATE TABLE slot_min_prices ( - eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE, - min_prices VARCHAR(200) NOT NULL -); - CREATE TABLE coordianator ( forger_addr BYTEA NOT NULL, eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,@@ -32,11 +27,19 @@ slot_num BIGINT NOT NULL
); CREATE TABLE exit_tree ( - batch_num BIGINT NOT NULL REFERENCES batch (batch_num) ON DELETE CASCADE, - account_idx BIGINT NOT NULL, + batch_num BIGINT REFERENCES batch (batch_num) ON DELETE CASCADE, + account_idx BIGINT, merkle_proof BYTEA NOT NULL, amount NUMERIC NOT NULL, nullifier BYTEA NOT NULL, + PRIMARY KEY (batch_num, account_idx) +); + +CREATE TABLE withdrawal ( + batch_num BIGINT, + account_idx BIGINT, + eth_block_num BIGINT REFERENCES block (eth_block_num) ON DELETE CASCADE, + FOREIGN KEY (batch_num, account_idx) REFERENCES exit_tree (batch_num, account_idx) ON DELETE CASCADE, PRIMARY KEY (batch_num, account_idx) );@@ -91,7 +94,30 @@ bjj BYTEA NOT NULL,
eth_addr BYTEA NOT NULL ); +CREATE TABLE rollup_vars ( + eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE, + forge_l1_timeout BYTEA NOT NULL, + fee_l1_user_tx BYTEA NOT NULL, + fee_add_token BYTEA NOT NULL, + tokens_hez BYTEA NOT NULL, + governance BYTEA NOT NULL +); + +CREATE TABLE consensus_vars ( + eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE, + slot_deadline INT NOT NULL, + close_auction_slots INT NOT NULL, + open_auction_slots INT NOT NULL, + min_bid_slots VARCHAR(200) NOT NULL, + outbidding INT NOT NULL, + donation_address BYTEA NOT NULL, + governance_address BYTEA NOT NULL, + allocation_ratio vARCHAR(200) +); + -- +migrate Down +DROP TABLE consensus_vars; +DROP TABLE rollup_vars; DROP TABLE account; DROP TABLE l2tx; DROP TABLE l1tx;@@ -100,5 +126,4 @@ DROP TABLE bid;
DROP TABLE exit_tree; DROP TABLE batch; DROP TABLE coordianator; -DROP TABLE slot_min_prices; DROP TABLE block;