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

mc-watcher keeps log of attestation verification reports #694

Merged
merged 13 commits into from
Feb 2, 2021

Conversation

eranrund
Copy link
Contributor

@eranrund eranrund commented Jan 27, 2021

Motivation

We'd like mc-watcher to support more thorough watching of the network. The first step in a series of upcoming improvements is to have it fetch the VerificationReport each time a new block signer is encountered, and store that in its database.

In this PR

  • mc-watcher sources are now configured via a sources.toml toml file. This change was necessary because we needed to introduce a map of tx source url -> consensus client url (so that when a new block is fetched from the tx source url, if a new block signer is detected, we can contact the node that created the block and get its VerificationReport). Passing this map via command line was gnarly, so this moved to a configuration file (similar to network.toml in mc-consensus-service)
  • The WatcherDB now includes additional databases (inside the LMDB file) for storing VerificationReports. The reports are indexed by (block signer public key, tx src url).

Future Work

  • Unit tests for VerificationReportsCollector. See VerificationReportsCollector happy flow unit test eranrund/mobilecoin#16
  • Create a utility that prints which block signers were used for each range of blocks, and the matching verification report (if available).
  • Make mc-watcher store all blocks fetched so that if the S3 sources ever goes away, the block data remains available locally.

.expect("Could not sync signatures");
let watcher = Watcher::new(watcher_db.clone(), transactions_fetcher, logger.clone());

let _verification_reports_collector = VerificationReportsCollector::new(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now we only collect verification reports inside the mc-watcher binary. mc-mobilecoind remains unchanged (it uses the WatcherDB and WatcherSyncThread to sync timestamps and block signatures but has no need for the verification reports).

@eranrund
Copy link
Contributor Author

When testing locally I used the following sources.toml:

[[sources]]
tx_source_url = "https://ledger.mobilecoinww.com/node1.prod.mobilecoinww.com/"
consensus_client_url = "mc://node1.prod.mobilecoinww.com:443/"

[[sources]]
tx_source_url = "https://ledger.mobilecoinww.com/node2.prod.mobilecoinww.com"
consensus_client_url = "mc://node2.prod.mobilecoinww.com:443/"

and the following command:
IAS_MODE=PROD SGX_MODE=HW cargo run -p mc-watcher --bin watcher -- --watcher-db /tmp/watcher-db --sources-path sources.toml

pub fn sync_signatures(
&self,
start: u64,
max_block_height: Option<u64>,
) -> Result<(), WatcherError> {
) -> Result<bool, WatcherError> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is part of a bugfix in main.rs that caused the loop to run indefinitely even when a max block was specified.

Copy link
Contributor

@sugargoat sugargoat left a comment

Choose a reason for hiding this comment

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

LGTM! A few superficial comments

use structopt::StructOpt;

const SYNC_RETRY_INTERVAL: Duration = Duration::from_secs(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this set here as opposed to either from config, or via using something like the retry crate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its there because realistically no-one will ever choose a different value. retry is inappropriate since this is actually a polling interval so the name is misleading. I'll add it to the command line config.

struct SourceConfig {
/// URL to use for pulling blocks.
///
/// For example: https://s3-us-west-1.amazonaws.com/mobilecoin.chain/node1.master.mobilecoin.com/
Copy link
Contributor

Choose a reason for hiding this comment

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

Would maybe put testnet URL as example

@@ -40,6 +52,17 @@ impl MetadataStoreSettings for WatcherDbMetadataStoreSettings {
/// Block signatures database name.
pub const BLOCK_SIGNATURES_DB_NAME: &str = "watcher_db:block_signatures";

/// VerificationReports database name.
pub const VERIFICATION_REPORTS_BY_BLOCK_SIGNER_DB_NANE: &str =
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub const VERIFICATION_REPORTS_BY_BLOCK_SIGNER_DB_NANE: &str =
pub const VERIFICATION_REPORTS_BY_BLOCK_SIGNER_DB_NAME: &str =

/// This is needed because LMDB limits the value size in DUP_SORT databases to 511 bytes, not
/// enough to fit the report. This database needs to be DUP_SORT since we want to support the
/// odd case of different reports showing up for the same signer/url pair. It shouldn't happen,
/// but we sure don't want to miss it if it does.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for documenting this

}

/// Get verification reports seen for a specific block signer/URL pair.
/// In theory there should ever be a single report (or none) for a given block_signer+src_url
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// In theory there should ever be a single report (or none) for a given block_signer+src_url
/// In theory there should only ever be a single report (or none) for a given block_signer+src_url

@eranrund eranrund merged commit 479aa72 into mobilecoinfoundation:master Feb 2, 2021
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