-
Notifications
You must be signed in to change notification settings - Fork 222
feat: Combined layout for transactions #3304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
infrmtcs
wants to merge
1
commit into
dat/migrate-block-transactions
Choose a base branch
from
dat/bench/combined
base: dat/migrate-block-transactions
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,48 +246,41 @@ func DeleteBlockHeaderByNumber(w db.KeyValueWriter, number uint64) error { | |
| return w.Delete(db.BlockHeaderByNumberKey(number)) | ||
| } | ||
|
|
||
| // TODO: Return TransactionReceipt instead of *TransactionReceipt. | ||
| func GetReceiptByHash( | ||
| func GetReceiptByBlockNumberAndIndex( | ||
| r db.KeyValueReader, | ||
| hash *felt.TransactionHash, | ||
| blockNumber uint64, | ||
| index uint64, | ||
| ) (*TransactionReceipt, error) { | ||
| val, err := TransactionBlockNumbersAndIndicesByHashBucket.RawValue().Get(r, hash) | ||
| blockTransactions, err := BlockTransactionsBucket.Get(r, blockNumber) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| receipt, err := ReceiptsByBlockNumberAndIndexBucket.RawKey().Get(r, val) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return &receipt, nil | ||
| return blockTransactions.Receipts().Get(int(index)) | ||
| } | ||
|
|
||
| func DeleteTxsAndReceipts(batch db.IndexedBatch, blockNum, numTxs uint64) error { | ||
| // remove txs and receipts | ||
| for i := range numTxs { | ||
| key := db.BlockNumIndexKey{ | ||
| Number: blockNum, | ||
| Index: i, | ||
| } | ||
| txn, err := TransactionsByBlockNumberAndIndexBucket.Get(batch, key) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| blockTransactions, err := BlockTransactionsBucket.Get(batch, blockNum) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := TransactionsByBlockNumberAndIndexBucket.Delete(batch, key); err != nil { | ||
| return err | ||
| } | ||
| if err := ReceiptsByBlockNumberAndIndexBucket.Delete(batch, key); err != nil { | ||
| return err | ||
| } | ||
| if err := BlockTransactionsBucket.Delete(batch, blockNum); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| transactions, err := blockTransactions.Transactions().All() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| txHash := (*felt.TransactionHash)(txn.Hash()) | ||
| for _, tx := range transactions { | ||
| txHash := (*felt.TransactionHash)(tx.Hash()) | ||
| if err := TransactionBlockNumbersAndIndicesByHashBucket.Delete(batch, txHash); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if l1handler, ok := txn.(*L1HandlerTransaction); ok { | ||
| if l1handler, ok := tx.(*L1HandlerTransaction); ok { | ||
| if err := DeleteL1HandlerTxnHashByMsgHash(batch, l1handler.MessageHash()); err != nil { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly here |
||
| return err | ||
| } | ||
|
|
@@ -390,33 +383,26 @@ func WriteBlockHeader(w db.KeyValueWriter, header *Header) error { | |
| } | ||
|
|
||
| // Returns all transactions in a given block | ||
| func GetTxsByBlockNum(r db.KeyValueReader, blockNum uint64) ([]Transaction, error) { | ||
| txs := []Transaction{} | ||
| txSeq := TransactionsByBlockNumberAndIndexBucket.Prefix().Add(blockNum).Scan(r) | ||
|
|
||
| for tx, err := range txSeq { | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| txs = append(txs, tx.Value) | ||
| func GetTransactionsByBlockNum(r db.KeyValueReader, blockNum uint64) ([]Transaction, error) { | ||
| blockTransactions, err := BlockTransactionsBucket.Get(r, blockNum) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return txs, nil | ||
| return blockTransactions.Transactions().All() | ||
| } | ||
|
|
||
| // Returns all receipts in a given block | ||
| func GetReceiptsByBlockNum(r db.KeyValueReader, blockNum uint64) ([]*TransactionReceipt, error) { | ||
| receipts := []*TransactionReceipt{} | ||
| receiptSeq := ReceiptsByBlockNumberAndIndexBucket.Prefix().Add(blockNum).Scan(r) | ||
|
|
||
| for receipt, err := range receiptSeq { | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| receipts = append(receipts, &receipt.Value) | ||
| func GetReceiptsByBlockNum( | ||
| r db.KeyValueReader, | ||
| blockNum uint64, | ||
| ) ([]*TransactionReceipt, error) { | ||
| blockTransactions, err := BlockTransactionsBucket.Get(r, blockNum) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return receipts, nil | ||
| return blockTransactions.Receipts().All() | ||
| } | ||
|
|
||
| func GetBlockByNumber(r db.KeyValueReader, blockNum uint64) (*Block, error) { | ||
|
|
@@ -425,57 +411,78 @@ func GetBlockByNumber(r db.KeyValueReader, blockNum uint64) (*Block, error) { | |
| return nil, err | ||
| } | ||
|
|
||
| txs, err := GetTxsByBlockNum(r, blockNum) | ||
| blockTransactions, err := BlockTransactionsBucket.Get(r, blockNum) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| allTransactions, err := blockTransactions.Transactions().All() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| receipts, err := GetReceiptsByBlockNum(r, blockNum) | ||
| allReceipts, err := blockTransactions.Receipts().All() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &Block{ | ||
| Header: header, | ||
| Transactions: txs, | ||
| Receipts: receipts, | ||
| Transactions: allTransactions, | ||
| Receipts: allReceipts, | ||
| }, nil | ||
| } | ||
|
|
||
| func WriteTxAndReceipt( | ||
| func WriteTransactionsAndReceipts( | ||
| w db.KeyValueWriter, | ||
| num, index uint64, | ||
| tx Transaction, | ||
| receipt *TransactionReceipt, | ||
| blockNumber uint64, | ||
| transactions []Transaction, | ||
| receipts []*TransactionReceipt, | ||
| ) error { | ||
| txHash := (*felt.TransactionHash)(tx.Hash()) | ||
| key := db.BlockNumIndexKey{ | ||
| Number: num, | ||
| Index: index, | ||
| } | ||
| for index, tx := range transactions { | ||
| txHash := (*felt.TransactionHash)(tx.Hash()) | ||
| key := db.BlockNumIndexKey{ | ||
| Number: blockNumber, | ||
| Index: uint64(index), | ||
| } | ||
|
|
||
| if err := TransactionBlockNumbersAndIndicesByHashBucket.Put(w, txHash, &key); err != nil { | ||
| return err | ||
| if err := TransactionBlockNumbersAndIndicesByHashBucket.Put(w, txHash, &key); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| if err := TransactionsByBlockNumberAndIndexBucket.Put(w, key, &tx); err != nil { | ||
| blockTransactions, err := NewBlockTransactions(transactions, receipts) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := ReceiptsByBlockNumberAndIndexBucket.Put(w, key, receipt); err != nil { | ||
| if err := BlockTransactionsBucket.Put(w, blockNumber, &blockTransactions); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func GetTxByHash(r db.KeyValueReader, hash *felt.TransactionHash) (Transaction, error) { | ||
| val, err := TransactionBlockNumbersAndIndicesByHashBucket.RawValue().Get(r, hash) | ||
| func GetTransactionByBlockNumberAndIndex( | ||
| r db.KeyValueReader, | ||
| blockNumber uint64, | ||
| index uint64, | ||
| ) (Transaction, error) { | ||
| blockTransactions, err := BlockTransactionsBucket.Get(r, blockNumber) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return blockTransactions.Transactions().Get(int(index)) | ||
| } | ||
|
|
||
| func GetTransactionByHash(r db.KeyValueReader, hash *felt.TransactionHash) (Transaction, error) { | ||
| blockNumIndex, err := TransactionBlockNumbersAndIndicesByHashBucket.Get(r, hash) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return TransactionsByBlockNumberAndIndexBucket.RawKey().Get(r, val) | ||
| return GetTransactionByBlockNumberAndIndex(r, blockNumIndex.Number, blockNumIndex.Index) | ||
| } | ||
|
|
||
| func GetAggregatedBloomFilter(r db.KeyValueReader, fromBlock, toBLock uint64) (AggregatedBloomFilter, error) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: I know this line is outside the scope of the PR but could you split the assignment from the if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason why we favor breaking it into 2 lines? IMO it's a good feature to scope the declaration of err, which avoid (possibly) wrong reuse of
err.