-
Notifications
You must be signed in to change notification settings - Fork 0
btcindexer: fix ingestor integration and types #186
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f82b336
fix(block-ingestor): integration issues and overall style
robert-zaremba 08b7333
update & unifiy CF binding names
robert-zaremba a1d9311
Merge branch 'master' into robert/fix-ingestor-integration
robert-zaremba e09095f
typecheck
robert-zaremba 86e1028
final
robert-zaremba 1b56f35
move types
robert-zaremba 3e3cd2e
Merge remote-tracking branch 'origin/master' into robert/fix-ingestor…
robert-zaremba e8422fe
fix
robert-zaremba cf4a61e
format
robert-zaremba 0a35974
Apply suggestions from code review
robert-zaremba 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 |
|---|---|---|
| @@ -1,38 +1,34 @@ | ||
| import { type PutBlock } from "./api/put-blocks"; | ||
| import { type BlockQueueRecord } from "@gonative-cc/lib/nbtc"; | ||
| import { type BlockQueueRecord, kvBlocksKey } from "@gonative-cc/lib/nbtc"; | ||
|
|
||
| /// Enequeue new blocks to the indexer processing queue. | ||
| export async function handleIngestBlocks( | ||
| blocks: PutBlock[], | ||
| blockStore: KVNamespace, | ||
| btcBlocksStore: KVNamespace, | ||
| blockQueue: Queue, | ||
| ): Promise<void> { | ||
| if (blocks.length === 0) { | ||
| throw new Error("Empty block batch"); | ||
| } | ||
|
|
||
| const blockMetas = blocks.map((block) => { | ||
| const blockHash = block.block.getId(); | ||
| const kvKey = `b:${block.network}:${blockHash}`; | ||
| return { block, blockHash, kvKey }; | ||
| }); | ||
|
|
||
| // Batch KV puts | ||
| const timestamp_ms = Date.now(); | ||
| const batch: MessageSendRequest<BlockQueueRecord>[] = []; | ||
| await Promise.all( | ||
| blockMetas.map((meta) => blockStore.put(meta.kvKey, meta.block.block.toBuffer())), | ||
| blocks.map((b) => { | ||
| const hash = b.block.getId(); | ||
| batch.push({ | ||
| body: { | ||
| hash, | ||
| timestamp_ms, | ||
| height: b.height, | ||
| network: b.network, | ||
| }, | ||
| }); | ||
| const kvKey = kvBlocksKey(b.network, b.block.getId()); | ||
| return btcBlocksStore.put(kvKey, b.block.toBuffer()); | ||
| }), | ||
| ); | ||
|
|
||
| const messages: BlockQueueRecord[] = []; | ||
| for (const meta of blockMetas) { | ||
| messages.push({ | ||
| hash: meta.blockHash, | ||
| height: meta.block.height, | ||
| network: meta.block.network, | ||
| kv_key: meta.kvKey, | ||
| }); | ||
| } | ||
|
|
||
| // Enqueue parsing requests | ||
| if (messages.length > 0) { | ||
| await blockQueue.sendBatch(messages.map((body: BlockQueueRecord) => ({ body }))); | ||
| if (batch.length > 0) { | ||
| await blockQueue.sendBatch(batch); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.