Skip to content
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

feat(base-node): improve contract utxo scanning #4208

Conversation

sdbondi
Copy link
Member

@sdbondi sdbondi commented Jun 16, 2022

Description

 feat(blockchain-db):      add {block_hash, output_type, contract_id} index to contract_index
 docs(chain-storage):      document mapping for each lmdb database
 feat(chain-storage):      replace fetch_all_constitutions with fetch_contract_outputs_for_block
 test(chain-storage):      add unit tests for fetch_contract_outputs_for_block
 feat(base-node-service):  replace get_constitutions with get_contract_outputs_for_block
 feat(base-node-grpc):     use get_contract_outputs_for_block to fetch constitutions
 test(cucumber):           mark `Publish contract acceptance` as broken
 test(cucumber):           fix command to publish contract utxos

Motivation and Context

get_all_constitutions is currently very inefficient and has to load the entire UTXO set. This PR adds a <block_hash, output_type, contract_id> index to contract_index db that allows efficient loading of contract outputs optionally filtered by type contained in a block.

The get_constitutions grpc method now takes in a start_block_hash and streams utxos starting from that hash.

How Has This Been Tested?

Additional unit tests
Manually, sync on igor

@sdbondi sdbondi changed the title Core add block hash contract index feat(base-node): improve contract utxo scanning Jun 16, 2022
@sdbondi sdbondi force-pushed the core-add-block-hash-contract-index branch 3 times, most recently from 6d7d53f to fbe1051 Compare June 17, 2022 13:11
@sdbondi sdbondi force-pushed the core-add-block-hash-contract-index branch 2 times, most recently from 463a84b to 10af53d Compare June 17, 2022 13:21
@sdbondi sdbondi force-pushed the core-add-block-hash-contract-index branch from 10af53d to 4487c7b Compare June 17, 2022 15:03
Copy link
Contributor

@brianp brianp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loosely reviewed, but heavily tested.

@@ -97,6 +97,7 @@ impl DanNode {
for output in outputs {
if let Some(sidechain_features) = output.features.sidechain_features {
let contract_id = sidechain_features.contract_id;
// TODO: expect will crash the validator node if the base node misbehaves
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in next PR.

@@ -106,11 +106,16 @@ impl BaseNodeClient for GrpcBaseNodeClient {
) -> Result<Vec<TransactionOutput>, DigitalAssetError> {
let inner = self.connection().await?;
let request = grpc::GetConstitutionsRequest {
// TODO: pass in the last block hash that was scanned
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in next PR

@stringhandler stringhandler merged commit 0fcde31 into tari-project:development Jun 20, 2022
@sdbondi sdbondi deleted the core-add-block-hash-contract-index branch June 20, 2022 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants