mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Add sync interface
This commit is contained in:
12
common/exittree.go
Normal file
12
common/exittree.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
)
|
||||
|
||||
type ExitTreeLeaf struct {
|
||||
AccountIdx Idx
|
||||
MerkleProof []byte
|
||||
Amount *big.Int
|
||||
Nullifier *big.Int
|
||||
}
|
||||
@@ -32,8 +32,6 @@ func (tx *L1Tx) Tx() *Tx {
|
||||
FromIdx: tx.FromIdx,
|
||||
ToIdx: tx.ToIdx,
|
||||
Amount: tx.Amount,
|
||||
Nonce: 0,
|
||||
Fee: 0,
|
||||
Type: tx.Type,
|
||||
}
|
||||
}
|
||||
|
||||
37
common/scvars.go
Normal file
37
common/scvars.go
Normal file
@@ -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
|
||||
}
|
||||
@@ -40,7 +40,12 @@ func NewHistoryDB(port int, host, user, password, dbname string) (*HistoryDB, er
|
||||
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,13 +65,38 @@ func (hdb *HistoryDB) GetBlocks(from, to uint64) ([]*common.Block, error) {
|
||||
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
|
||||
func (hdb *HistoryDB) addBids(bids []common.Bid) error {
|
||||
// TODO: check the coordinator info
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestAddBlock(t *testing.T) {
|
||||
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 @@ func TestBids(t *testing.T) {
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,6 @@ CREATE TABLE block (
|
||||
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,14 +27,22 @@ CREATE TABLE batch (
|
||||
);
|
||||
|
||||
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)
|
||||
);
|
||||
|
||||
CREATE TABLE bid (
|
||||
slot_num BIGINT NOT NULL,
|
||||
bid_value BYTEA NOT NULL, -- (check if we can do a max(), if not add float for order purposes)
|
||||
@@ -91,7 +94,30 @@ CREATE TABLE account (
|
||||
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;
|
||||
Reference in New Issue
Block a user