SIGBlockchain / project_aurum

SIG Blockchain blockchain project in Go
https://acm.cs.uic.edu/sigblockchain
MIT License
7 stars 0 forks source link

Get a batch of blocks SQL Query #421

Closed kastolars closed 5 years ago

kastolars commented 5 years ago

In order to create the Blockchain Streamer, we need to create a query that extracts a large chunk of the blockchain file.

Currently our Metadata table has the following columns

image

Example: I want to extract block 478. I look in the metadata table at the row that has 478, then I look at its position and height. Suppose its position is 3016, and its size is 289. I will open the blockchain file, move my file pointer to index 3016, and read in 289 bytes from that position. You can look at this function to see how this is done: https://github.com/SIGBlockchain/project_aurum/blob/master/internal/blockchain/blockchain.go#L96

Batching blocks is a bit different. We need to make a query that given height h and a number n, extracts blocks from h to h + (n - 1). So if I give this query h = 478 and n = 5, that means I want to extract blocks 478, 479, 480, 481, and 482.

This is a little different from the function I linked above. Given a height h and a count n, go into the table and return rows with columns height, size, and position for all blocks x within the range:

h >= x < ( h + n )