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/stackerdb chunk db #3558

Merged
merged 24 commits into from
Aug 16, 2023
Merged

Feat/stackerdb chunk db #3558

merged 24 commits into from
Aug 16, 2023

Conversation

jcnelson
Copy link
Member

@jcnelson jcnelson commented Feb 8, 2023

This implements the Stacker DB chunk storage database, as part of breaking apart #3534.

@jcnelson jcnelson added the sbtc label Feb 8, 2023
@jcnelson jcnelson changed the base branch from develop to feat/stackerdb-discovery February 8, 2023 19:02
@codecov
Copy link

codecov bot commented Feb 8, 2023

Codecov Report

Merging #3558 (e4747a8) into develop (c356b84) will decrease coverage by 0.01%.
Report is 62 commits behind head on develop.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           develop    #3558      +/-   ##
===========================================
- Coverage     0.16%    0.16%   -0.01%     
===========================================
  Files          305      315      +10     
  Lines       280694   282789    +2095     
===========================================
  Hits           469      469              
- Misses      280225   282320    +2095     
Files Changed Coverage Δ
stackslib/src/burnchains/bitcoin/indexer.rs 0.00% <0.00%> (ø)
stackslib/src/chainstate/coordinator/mod.rs 0.00% <0.00%> (ø)
stackslib/src/main.rs 0.00% <0.00%> (ø)
stackslib/src/net/chat.rs 0.00% <0.00%> (ø)
stackslib/src/net/codec.rs 0.00% <0.00%> (ø)
stackslib/src/net/connection.rs 0.00% <0.00%> (ø)
stackslib/src/net/db.rs 0.00% <0.00%> (ø)
stackslib/src/net/mod.rs 0.00% <0.00%> (ø)
stackslib/src/net/neighbors/comms.rs 0.00% <0.00%> (ø)
stackslib/src/net/neighbors/db.rs 0.00% <0.00%> (ø)
... and 15 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

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.

I have a couple of comments and requests that should be addressed:

  1. Dynamic table names are pretty close to a sql anti-pattern and can lead to issues down the road (as well as requiring contract name sanitization), and so I think unless there's a very compelling reason to do this, it should be avoided.
  2. StackerDB refers to two different things in the codebase (and the docs) and I think it's making the codebase confusing (sometimes "stackerdb" is a contract identifier, other times its the database storing multiple "stackerdb"s), and there's no better time than now to try to fix this (if it isn't fixed now, the codebase will probably have to live with this confusion forever)

src/net/stackerdb/mod.rs Outdated Show resolved Hide resolved

/// This module contains methods for interacting with the data contained within the messages
use crate::net::{
Error as net_error, StackerDBChunkData, StackerDBChunkInvData, StackerDBGetChunkData,
Copy link
Member

Choose a reason for hiding this comment

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

I think StackerDBChunkData should be in the net::stackerdb module rather than in net

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 and the other StackerDB* structs are new protocol messages, whose definitions IMHO belong with the other message definitions.

src/net/stackerdb/db.rs Outdated Show resolved Hide resolved
format!("stackerdb_{}", normalized_name)
}

/// Load up chunk metadata from the database, given the primary key.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Load up chunk metadata from the database, given the primary key.
/// Load a chunk's metadata from the database, keyed by the chunk's smart contract, the reward cycle consensus hash, and the chunk identifier.

Looking at this PR after #3551 and #3552, I think there's a naming conflict with "StackerDB" -- you refer to the local database as "the StackerDB", but also, throughout the code, different smart contracts' associated chunk storage is each called "a StackerDB". This is already kind of confusing to me, and this is pretty early on in the life of this code, so I think we'd probably be better served with a different way to talk about these things.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm having a hard time understanding what the ask here is. The "smart contracts' associated chunk storage" is a stacker DB. The node maintains a local replica of that state for each stacker DB it subscribes to. But, I don't see the value in calling the local replica by a different name, since I think that's already understood simply because a single process cannot be a whole p2p network.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you're referring to the fact that StackerDB the struct currently stores all stacker DB chunks for all subscribed stacker DBs? If so, then I'll rename StackerDB to StackerDBSet to disambiguate it.

Comment on lines 270 to 272
/// Set up a database's storage slots.
/// The slots must be in a deterministic order, since they are used to determine the chunk ID
/// (and thus the key used to authenticate them)
Copy link
Member

Choose a reason for hiding this comment

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

What is a storage slot? It seems like this method is just writing empty data into the table. Why is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's done this way because the follow-on StackerDB state sync PR needs to be able to extract the version vector for all of the DB's slots. But in order to do that, those slots either have to be instantiated, or we need some kind of sparse version vector calculation. The latter requires one SQL query per slot (since if slot data does not exist, we'd need to synthesize it on the fly), whereas this only requires a single query which can use an index.

src/net/stackerdb/db.rs Outdated Show resolved Hide resolved
@igorsyl igorsyl mentioned this pull request Feb 10, 2023
7 tasks
@pavitthrap pavitthrap added the frozen PRs that are on hold label Mar 21, 2023
@kantai kantai removed the frozen PRs that are on hold label Aug 2, 2023
src/net/stackerdb/bits.rs Outdated Show resolved Hide resolved
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.

Just a few more comments over my last review, which I think is still valid -- mostly, I think that programmatic table construction should be avoided unless there is a really compelling reason.

src/net/stackerdb/bits.rs Outdated Show resolved Hide resolved
src/net/stackerdb/bits.rs Outdated Show resolved Hide resolved
src/net/stackerdb/bits.rs Outdated Show resolved Hide resolved
src/net/stackerdb/tests/db.rs Outdated Show resolved Hide resolved
@jcnelson jcnelson requested review from kantai and obycode and removed request for donpdonp August 4, 2023 04:46
Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

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

LGTM!

@jcnelson
Copy link
Member Author

Hey @kantai, this is ready for re-review when you get the chance. Thanks!

@jcnelson jcnelson changed the base branch from feat/stackerdb-discovery to develop August 11, 2023 03:38
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.

This looks good to me, my remaining feedback is pretty superficial.

stackslib/src/net/codec.rs Show resolved Hide resolved
stackslib/src/net/mod.rs Show resolved Hide resolved
stackslib/src/net/mod.rs Show resolved Hide resolved
stackslib/src/net/codec.rs Show resolved Hide resolved
stackslib/src/net/mod.rs Show resolved Hide resolved
stackslib/src/net/stackerdb/db.rs Show resolved Hide resolved
stackslib/src/net/mod.rs Show resolved Hide resolved
stackslib/src/net/mod.rs Show resolved Hide resolved
stackslib/src/net/stackerdb/db.rs Show resolved Hide resolved
stackslib/src/net/stackerdb/db.rs Show resolved Hide resolved
@jcnelson jcnelson requested a review from kantai August 15, 2023 15:20
@kantai kantai removed the request for review from igorsyl August 15, 2023 21:08
@jcnelson
Copy link
Member Author

@kantai I addressed all your feedback in feat/stackerdb-rpc (by mistake -- was using the wrong tab). Is that okay? It'll find its way into this branch.

@jcnelson jcnelson merged commit 7581e6d into develop Aug 16, 2023
1 check passed
@blockstack-devops
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@stacks-network stacks-network locked as resolved and limited conversation to collaborators Nov 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

5 participants