Add usefull methods for reorg

This commit is contained in:
Arnau B
2020-08-21 16:59:30 +02:00
parent 1cbf54acc7
commit c108739c24
7 changed files with 28 additions and 12 deletions

View File

@@ -54,7 +54,12 @@ func (hdb *HistoryDB) addBlocks(blocks []common.Block) error {
)
}
// GetBlocks retrrieve blocks from the DB
// GetBlock retrieve a block from the DB, given a block number
func (hdb *HistoryDB) GetBlock(blockNum uint64) (*common.Block, error) {
return nil, nil
}
// GetBlocks retrieve blocks from the DB, given a range of block numbers defined by from and to
func (hdb *HistoryDB) GetBlocks(from, to uint64) ([]*common.Block, error) {
var blocks []*common.Block
err := meddler.QueryAll(
@@ -65,6 +70,16 @@ func (hdb *HistoryDB) GetBlocks(from, to uint64) ([]*common.Block, error) {
return blocks, err
}
// GetLastBlock retrieve the block with the highest block number from the DB
func (hdb *HistoryDB) GetLastBlock() (*common.Block, error) {
return nil, nil
}
// GetLastBatchNum returns the BatchNum of the latest forged batch
func (hdb *HistoryDB) GetLastBatchNum() (*common.BatchNum, error) {
return nil, nil
}
// 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 {

View File

@@ -30,7 +30,7 @@ CREATE TABLE exit_tree (
batch_num BIGINT REFERENCES batch (batch_num) ON DELETE CASCADE,
account_idx BIGINT,
merkle_proof BYTEA NOT NULL,
amount NUMERIC NOT NULL,
balance NUMERIC NOT NULL,
nullifier BYTEA NOT NULL,
PRIMARY KEY (batch_num, account_idx)
);
@@ -72,7 +72,8 @@ CREATE TABLE l1tx (
token_id INT NOT NULL REFERENCES token (token_id),
amount NUMERIC NOT NULL,
load_amount BYTEA NOT NULL,
eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE
eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,
tx_type VARCHAR(40) NOT NULL
);
CREATE TABLE l2tx (
@@ -83,7 +84,8 @@ CREATE TABLE l2tx (
to_idx BIGINT NOT NULL,
amount NUMERIC NOT NULL,
fee INT NOT NULL,
nonce BIGINT NOT NULL
nonce BIGINT NOT NULL,
tx_type VARCHAR(40) NOT NULL
);
CREATE TABLE account (

View File

@@ -22,7 +22,8 @@ CREATE TABLE tx_pool (
signature BYTEA NOT NULL,
timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL,
absolute_fee NUMERIC,
absolute_fee_update TIMESTAMP WITHOUT TIME ZONE
absolute_fee_update TIMESTAMP WITHOUT TIME ZONE,
tx_type VARCHAR(40) NOT NULL
);
CREATE TABLE account_creation_auth (