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/appchain network improvements #2862

Merged
merged 45 commits into from
Dec 9, 2021

Conversation

jcnelson
Copy link
Member

@jcnelson jcnelson commented Oct 1, 2021

This PR backports network fixes and improvements from #2857 that would benefit the Stacks chain. They are:

  • Adds the /v2/headers endpoint, which returns a sequence of SIP-003-encoded block headers and consensus hashes (see the ExtendedStacksHeader struct that this PR adds to represent this data).

  • Adds the /v2/data_var endpoint, which returns a contract's data variable value and a MARF proof of its existence.

  • Makes the p2p state machine more aggressive at reacting to newly-arrived BlocksAvailable and MicroblocksAvailable messages for block and microblock streams that this node does not have. If such messages arrive during an inventory sync, the p2p state machine will immediately transition from the inventory sync work state to the block downloader work state, and immediately proceed to fetch the available block or microblock stream.

…d of write_next() for byte arrays (since they're not actually arrays in this case)
…le to stream back a list of Stacks block headers, in service of the new /v2/headers RPC endpoint
…ndexing at a particular sortition height, even if the downloader isn't idle.
…r data we don't have, and if the P2P state-machine is doing an inv-sync, then *immediately* stop the inv sync, switch to the downloader step, and point the downloader to the sortition of the block or microblock that is now available. This makes the p2p network much more aggressive about fetching newly-arrived blocks and confirmed microblock streams
…ata capable of representing a headers stream
Copy link
Contributor

@pavitthrap pavitthrap left a comment

Choose a reason for hiding this comment

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

lgtm - just had a few comments

@@ -894,8 +894,10 @@ impl BlockDownloader {
&mut self,
block_sortition_height: u64,
ibd: bool,
force: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not super clear what force is to me - perhaps add comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

src/net/p2p.rs Outdated
Comment on lines 3674 to 3677
if inv.block_bitvec.len() > 0 {
inv.block_bitvec[0] == 0
} else {
false
Copy link
Contributor

Choose a reason for hiding this comment

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

Could add method to BlocksInvData for this (suggestion applies to the microblock fn below)

src/net/rpc.rs Outdated
ref mut convo_client,
ref mut peer_server,
ref mut convo_server| {
let principal =
Copy link
Contributor

Choose a reason for hiding this comment

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

Not using principal in function? Same for test below

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup; removed


#[test]
#[ignore]
fn test_rpc_get_data_var_unconfirmed() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps could add a test trying to retrieve a var that does not exist?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, added

.unwrap();
headers.push(next_header);
}
if header_ptr.len() == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a similar check before the loop (for the case where header_bytes has length 0)?

Copy link
Member Author

Choose a reason for hiding this comment

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

This code is not called anywhere anymore, so I'll drop it.

Copy link
Contributor

@gregorycoppola gregorycoppola left a comment

Choose a reason for hiding this comment

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

Thanks for the improvements. Sorry for not getting to this.

In the future might be a good exercise to break up three such changes, so it is easier to understand each one on its own.

@@ -77,6 +77,96 @@ Reason types without additional information will not have a

Get current PoX-relevant information. See OpenAPI [spec](./rpc/openapi.yaml) for details.

### GET /v2/headers/[Count]
Copy link
Member

Choose a reason for hiding this comment

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

It'd be better for the new endpoints to be documented in the OpenAPI spec (./rpc/openapi.yaml). That gets used for autogenerating API docs in a couple different places, but also is used by the stacks-blockchain-api to do schema validation.

When we adding the openapi.yaml spec to this repo, we left this doc in place without a plan for deprecating it, however, I think it only makes sense to have one specification, and of the two, I'd prefer the OpenAPI spec.

Copy link
Member Author

Choose a reason for hiding this comment

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

Damn, forgot to do this. Will send a separate PR.

@codecov
Copy link

codecov bot commented Dec 6, 2021

Codecov Report

Merging #2862 (591cbfe) into develop (05f0cd3) will decrease coverage by 0.73%.
The diff coverage is 50.47%.

❗ Current head 591cbfe differs from pull request most recent head e89c568. Consider uploading reports for the commit e89c568 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2862      +/-   ##
===========================================
- Coverage    82.88%   82.15%   -0.74%     
===========================================
  Files          235      235              
  Lines       189222   189697     +475     
===========================================
- Hits        156840   155837    -1003     
- Misses       32382    33860    +1478     
Impacted Files Coverage Δ
.../chainstate/burn/operations/leader_key_register.rs 96.38% <ø> (+0.16%) ⬆️
src/chainstate/burn/operations/mod.rs 46.04% <ø> (ø)
src/chainstate/burn/operations/stack_stx.rs 72.98% <0.00%> (-1.07%) ⬇️
src/net/server.rs 61.32% <ø> (-6.39%) ⬇️
src/types/chainstate.rs 90.14% <ø> (ø)
src/types/proof.rs 12.00% <0.00%> (-0.50%) ⬇️
src/net/rpc.rs 32.12% <10.90%> (-4.11%) ⬇️
src/net/http.rs 76.38% <19.48%> (-2.96%) ⬇️
src/net/inv.rs 67.59% <30.43%> (+0.22%) ⬆️
src/chainstate/stacks/db/mod.rs 86.83% <33.33%> (+0.06%) ⬆️
... and 88 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f225538...e89c568. Read the comment docs.

@jcnelson jcnelson requested a review from kantai December 7, 2021 18:19
const DECODE_HEADER_USAGE: &str = "blockstack-cli (options) decode-header [block-path-or-stdin]

The decode-header command decodes a serialized Stacks header and prints it to stdout as JSON.
The header, if given, must be a hex string. Alternatively, you may pass - instead, and the
Copy link
Member

Choose a reason for hiding this comment

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

Back quoting - will make the last sentence more clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

let block_header: StacksBlockHeader = StacksChainState::consensus_load(block_path)?;
Ok(Some(block_header))
}

/// Load up an anchored block header from the chunk store.
/// Returns Ok(Some(blockheader)) if found.
/// Returns Ok(None) if this block was found, but is known to be invalid
/// Returns Err(...) on not found or I/O error
pub fn load_block_header(
Copy link
Member

Choose a reason for hiding this comment

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

Can load_block_header just invoke inner_load_block_header after computing the block_path?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@kantai kantai left a comment

Choose a reason for hiding this comment

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

LGTM! Just some light nits

@jcnelson jcnelson merged commit 1dead86 into develop Dec 9, 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.

4 participants