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/chain-id #3111

Merged
merged 29 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f8c824a
feat: add `chain-id` global variable, which evaluates to the chain_id…
jcnelson Apr 22, 2022
450039b
chore: add unit tests for `chain-id` variable
jcnelson Apr 22, 2022
16da7ba
chore: plumb through chain_id into ClarityInstance and its dependant …
jcnelson Apr 22, 2022
a94dfe5
chore: sync APIs to pass along chain_id
jcnelson Apr 22, 2022
4f30cf4
chore: sync APIs to pass along chain_id, and add docs for `chain-id`
jcnelson Apr 22, 2022
1a04a10
chore: pass through StacksChainState's chain_id into Clarity-related …
jcnelson Apr 22, 2022
ea9552c
chore: sync APIs in tests to require chain_id
jcnelson Apr 22, 2022
3a41660
refactor: put chain IDs in stacks_common::consts
jcnelson Apr 22, 2022
4f543c0
chore: pass through chain ID into RPC calls that interact with Clarity
jcnelson Apr 22, 2022
309b4e7
chore: deduce and pass reasonable chain ID values for the clarity-cli…
jcnelson Apr 22, 2022
cb6861d
fix: add separate DB migration function so the chains coordinator can…
jcnelson Apr 22, 2022
485e450
feat: add function to check and migrate chainstate DBs if they exist
jcnelson Apr 22, 2022
dfc4c49
fix: an always-allowed peer is already authenticated since we have it…
jcnelson Apr 22, 2022
32741c8
chore: add OldSchema(..) and TooOldForEpoch error variants for schema…
jcnelson Apr 22, 2022
889bc9b
fix: update the public key of an always-allowed peer on boot-up, as w…
jcnelson Apr 22, 2022
8f472cf
fix: if the chainstate DBs exist already, then they must be migrated …
jcnelson Apr 22, 2022
abaf6cf
fix: use Epoch21 with Clarity2
jcnelson Apr 23, 2022
118187d
Merge pull request #3112 from stacks-network/fix/first-block-header
jcnelson Apr 25, 2022
906130a
feat: rename blockstack-core to stacks-inspect
kantai Apr 25, 2022
1d46436
fix: update build scripts, etc. with stacks-inspect
kantai Apr 25, 2022
16fe381
Merge pull request #3113 from stacks-network/feat/rename-core
kantai Apr 26, 2022
9a07bbc
chore: use a *test-only* helper method to choose the right chain ID
jcnelson Apr 27, 2022
6f93b7d
Merge branch 'next' into feat/chain-id
jcnelson Apr 27, 2022
46f38d6
fix: compile-time errors in test_only_mainnet_to_chain_id
jcnelson Apr 27, 2022
4c8204d
Merge branch 'develop' into feat/chain-id
jcnelson Apr 27, 2022
35f8954
fix: only import test code in test gates
jcnelson Apr 27, 2022
be117c8
fix: gate import of test code for tests only
jcnelson Apr 27, 2022
7307507
fix: clean up unused imports and use test_only_mainnet_to_chain_id() …
jcnelson Apr 27, 2022
2747901
Merge branch 'next' into feat/chain-id
jcnelson Apr 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/actions/docsgen/Dockerfile.docsgen
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ RUN cargo build

RUN mkdir /out

RUN /src/target/debug/blockstack-core docgen | jq . > /out/clarity-reference.json
RUN /src/target/debug/blockstack-core docgen_boot | jq . > /out/boot-contracts-reference.json
RUN /src/target/debug/stacks-inspect docgen | jq . > /out/clarity-reference.json
RUN /src/target/debug/stacks-inspect docgen_boot | jq . > /out/boot-contracts-reference.json

FROM scratch AS export-stage
COPY --from=build /out/clarity-reference.json /
Expand Down
8 changes: 4 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"cargo": {
"args": [
"build",
"--bin=blockstack-core",
"--bin=stacks-inspect",
"--package=blockstack-core"
],
"filter": {
"name": "blockstack-core",
"name": "stacks-inspect",
"kind": "bin"
}
},
Expand Down Expand Up @@ -118,11 +118,11 @@
"args": [
"test",
"--no-run",
"--bin=blockstack-core",
"--bin=stacks-inspect",
"--package=blockstack-core"
],
"filter": {
"name": "blockstack-core",
"name": "stacks-inspect",
"kind": "bin"
}
},
Expand Down
16 changes: 9 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,27 @@ the node to spend up to 30 minutes migrating the data to a new schema.
### Changed
- The MARF implementation will now defer calculating the root hash of a new trie
until the moment the trie is committed to disk. This avoids gratuitous hash
calculations, and yields a performance improvement of anywhere between 10x and
200x (#3041).
calculations, and yields a performance improvement of anywhere between 10x and
200x (#3041).
- The MARF implementation will now store tries to an external file for instances
where the tries are expected to exceed the SQLite page size (namely, the
Clarity database). This improves read performance by a factor of 10x to 14x
(#3059).
Clarity database). This improves read performance by a factor of 10x to 14x
(#3059).
- The MARF implementation may now cache trie nodes in RAM if directed to do so
by an environment variable (#3042).
- Sortition processing performance has been improved by about an order of
magnitude, by avoiding a slew of expensive database reads (#3045). WARNING:
applying this change to an existing chainstate directory will take a few
minutes when the node starts up.
applying this change to an existing chainstate directory will take a few
minutes when the node starts up.
- Updated chains coordinator so that before a Stacks block or a burn block is processed,
an event is sent through the event dispatcher. This fixes #3015.
- Expose a node's public key and public key hash160 (i.e. what appears in
/v2/neighbors) via the /v2/info API endpoint (#3046)
- Reduced the default subsequent block attempt timeout from 180 seconds to 30
seconds, based on benchmarking the new MARF performance data during a period
of network congestion (#3098)
of network congestion (#3098)
- The `blockstack-core` binary has been renamed to `stacks-inspect`.
This binary provides CLI tools for chain and mempool inspection.

## [2.05.0.1.0]

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ name = "blockstack_lib"
path = "src/lib.rs"

[[bin]]
name = "blockstack-core"
name = "stacks-inspect"
path = "src/main.rs"

[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion build-scripts/Dockerfile.linux-arm64
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ RUN CC=aarch64-linux-gnu-gcc \
RUN mkdir /out && cp -R /src/target/aarch64-unknown-linux-gnu/release/. /out

FROM scratch AS export-stage
COPY --from=build /out/blockstack-core /out/blockstack-cli /out/clarity-cli /out/stacks-node /
COPY --from=build /out/stacks-inspect /out/blockstack-cli /out/clarity-cli /out/stacks-node /
2 changes: 1 addition & 1 deletion build-scripts/Dockerfile.linux-armv7
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ RUN CC=arm-linux-gnueabihf-gcc \
RUN mkdir /out && cp -R /src/target/armv7-unknown-linux-gnueabihf/release/. /out

FROM scratch AS export-stage
COPY --from=build /out/blockstack-core /out/blockstack-cli /out/clarity-cli /out/stacks-node /
COPY --from=build /out/stacks-inspect /out/blockstack-cli /out/clarity-cli /out/stacks-node /
2 changes: 1 addition & 1 deletion build-scripts/Dockerfile.linux-musl-x64
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ RUN CC=musl-gcc \
RUN mkdir /out && cp -R /src/target/x86_64-unknown-linux-musl/release/. /out

FROM scratch AS export-stage
COPY --from=build /out/blockstack-core /out/blockstack-cli /out/clarity-cli /out/stacks-node /
COPY --from=build /out/stacks-inspect /out/blockstack-cli /out/clarity-cli /out/stacks-node /
2 changes: 1 addition & 1 deletion build-scripts/Dockerfile.linux-x64
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ RUN cargo build --release --workspace --target x86_64-unknown-linux-gnu
RUN mkdir /out && cp -R /src/target/x86_64-unknown-linux-gnu/release/. /out

FROM scratch AS export-stage
COPY --from=build /out/blockstack-core /out/blockstack-cli /out/clarity-cli /out/stacks-node /
COPY --from=build /out/stacks-inspect /out/blockstack-cli /out/clarity-cli /out/stacks-node /
2 changes: 1 addition & 1 deletion build-scripts/Dockerfile.macos-arm64
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ RUN . /opt/osxcross/env-macos-aarch64 && \
RUN mkdir /out && cp -R /src/target/aarch64-apple-darwin/release/. /out

FROM scratch AS export-stage
COPY --from=build /out/blockstack-core /out/blockstack-cli /out/clarity-cli /out/stacks-node /
COPY --from=build /out/stacks-inspect /out/blockstack-cli /out/clarity-cli /out/stacks-node /
2 changes: 1 addition & 1 deletion build-scripts/Dockerfile.macos-x64
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ RUN . /opt/osxcross/env-macos-x86_64 && \
RUN mkdir /out && cp -R /src/target/x86_64-apple-darwin/release/. /out

FROM scratch AS export-stage
COPY --from=build /out/blockstack-core /out/blockstack-cli /out/clarity-cli /out/stacks-node /
COPY --from=build /out/stacks-inspect /out/blockstack-cli /out/clarity-cli /out/stacks-node /
2 changes: 1 addition & 1 deletion build-scripts/Dockerfile.windows-x64
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ RUN CC_x86_64_pc_windows_gnu=x86_64-w64-mingw32-gcc \
RUN mkdir /out && cp -R /src/target/x86_64-pc-windows-gnu/release/. /out

FROM scratch AS export-stage
COPY --from=build /out/blockstack-core.exe /out/blockstack-cli.exe /out/clarity-cli.exe /out/stacks-node.exe /
COPY --from=build /out/stacks-inspect.exe /out/blockstack-cli.exe /out/clarity-cli.exe /out/stacks-node.exe /
14 changes: 7 additions & 7 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:
cargo build
- run:
command: |
./target/debug/blockstack-core local initialize db &&
./target/debug/blockstack-core local check sample-contracts/tokens.clar db &&
./target/debug/blockstack-core local launch S1G2081040G2081040G2081040G208105NK8PE5.tokens sample-contracts/tokens.clar db &&
./target/debug/blockstack-core local check sample-contracts/names.clar db &&
./target/debug/blockstack-core local launch S1G2081040G2081040G2081040G208105NK8PE5.names sample-contracts/names.clar db &&
./target/debug/blockstack-core local execute db S1G2081040G2081040G2081040G208105NK8PE5.tokens mint! SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR u100000
./target/debug/stacks-inspect local initialize db &&
./target/debug/stacks-inspect local check sample-contracts/tokens.clar db &&
./target/debug/stacks-inspect local launch S1G2081040G2081040G2081040G208105NK8PE5.tokens sample-contracts/tokens.clar db &&
./target/debug/stacks-inspect local check sample-contracts/names.clar db &&
./target/debug/stacks-inspect local launch S1G2081040G2081040G2081040G208105NK8PE5.names sample-contracts/names.clar db &&
./target/debug/stacks-inspect local execute db S1G2081040G2081040G2081040G208105NK8PE5.tokens mint! SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR u100000
- run:
command: |
echo "(get-balance 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR)" | ./target/debug/blockstack-core local eval S1G2081040G2081040G2081040G208105NK8PE5.tokens db
echo "(get-balance 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR)" | ./target/debug/stacks-inspect local eval S1G2081040G2081040G2081040G208105NK8PE5.tokens db
unit_tests_with_cov:
machine: true
working_directory: ~/blockstack
Expand Down
4 changes: 3 additions & 1 deletion clarity/src/vm/analysis/arithmetic_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ impl<'a> ArithmeticOnlyChecker<'a> {
{
match native_var {
ContractCaller | TxSender | TotalLiquidMicroSTX | BlockHeight | BurnBlockHeight
| Regtest | TxSponsor | Mainnet => Err(Error::VariableForbidden(native_var)),
| Regtest | TxSponsor | Mainnet | ChainId => {
Err(Error::VariableForbidden(native_var))
}
NativeNone | NativeTrue | NativeFalse => Ok(()),
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions clarity/src/vm/analysis/arithmetic_checker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fn test_variables_fail_arithmetic_check_clarity1() {
),
("(define-private (foo) tx-sponsor?)", Ok(())),
("(define-private (foo) is-in-mainnet)", Ok(())),
("(define-private (foo) chain-id)", Ok(())),
];

for (contract, result) in tests.iter() {
Expand Down Expand Up @@ -170,6 +171,10 @@ fn test_variables_fail_arithmetic_check_clarity2() {
"(define-private (foo) is-in-mainnet)",
Err(VariableForbidden(NativeVariables::Mainnet)),
),
(
"(define-private (foo) chain-id)",
Err(VariableForbidden(NativeVariables::ChainId)),
),
];

for (contract, result) in tests.iter() {
Expand Down
1 change: 1 addition & 0 deletions clarity/src/vm/analysis/type_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ fn type_reserved_variable(variable_name: &str, version: &ClarityVersion) -> Opti
TotalLiquidMicroSTX => TypeSignature::UIntType,
Regtest => TypeSignature::BoolType,
Mainnet => TypeSignature::BoolType,
ChainId => TypeSignature::UIntType,
};
Some(var_type)
} else {
Expand Down
6 changes: 4 additions & 2 deletions clarity/src/vm/clarity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub trait ClarityConnection {
fn with_readonly_clarity_env<F, R>(
&mut self,
mainnet: bool,
chain_id: u32,
sender: PrincipalData,
sponsor: Option<PrincipalData>,
cost_track: LimitedCostTracker,
Expand All @@ -129,8 +130,9 @@ pub trait ClarityConnection {
{
let epoch_id = self.get_epoch();
self.with_clarity_db_readonly_owned(|clarity_db| {
let mut vm_env =
OwnedEnvironment::new_cost_limited(mainnet, clarity_db, cost_track, epoch_id);
let mut vm_env = OwnedEnvironment::new_cost_limited(
mainnet, chain_id, clarity_db, cost_track, epoch_id,
);
let result = vm_env
.execute_in_env(sender, sponsor, to_do)
.map(|(result, _, _)| result);
Expand Down
25 changes: 22 additions & 3 deletions clarity/src/vm/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ use crate::vm::version::ClarityVersion;

use crate::vm::coverage::CoverageReporter;

use crate::vm::tests::test_only_mainnet_to_chain_id;
obycode marked this conversation as resolved.
Show resolved Hide resolved

use stacks_common::consts::CHAIN_ID_TESTNET;

use serde::Serialize;

pub const MAX_CONTEXT_DEPTH: u16 = 256;
Expand Down Expand Up @@ -204,6 +208,8 @@ pub struct GlobalContext<'a> {
pub coverage_reporting: Option<CoverageReporter>,
/// This is the epoch of the the block that this transaction is executing within.
epoch_id: StacksEpochId,
/// This is the chain ID of the transaction
pub chain_id: u32,
obycode marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -543,7 +549,13 @@ impl<'a> OwnedEnvironment<'a> {
pub fn new(database: ClarityDatabase<'a>) -> OwnedEnvironment<'a> {
let epoch = StacksEpochId::Epoch2_05;
OwnedEnvironment {
context: GlobalContext::new(false, database, LimitedCostTracker::new_free(), epoch),
context: GlobalContext::new(
false,
CHAIN_ID_TESTNET,
database,
LimitedCostTracker::new_free(),
epoch,
),
default_contract: ContractContext::new(
QualifiedContractIdentifier::transient(),
ClarityVersion::Clarity1,
Expand All @@ -560,8 +572,10 @@ impl<'a> OwnedEnvironment<'a> {
) -> OwnedEnvironment<'a> {
let cost_track = LimitedCostTracker::new_max_limit(&mut database, epoch, use_mainnet)
.expect("FAIL: problem instantiating cost tracking");
let chain_id = test_only_mainnet_to_chain_id(use_mainnet);

OwnedEnvironment {
context: GlobalContext::new(use_mainnet, database, cost_track, epoch),
context: GlobalContext::new(use_mainnet, chain_id, database, cost_track, epoch),
default_contract: ContractContext::new(
QualifiedContractIdentifier::transient(),
ClarityVersion::Clarity1,
Expand All @@ -580,12 +594,14 @@ impl<'a> OwnedEnvironment<'a> {

pub fn new_free(
mainnet: bool,
chain_id: u32,
database: ClarityDatabase<'a>,
epoch_id: StacksEpochId,
) -> OwnedEnvironment<'a> {
OwnedEnvironment {
context: GlobalContext::new(
mainnet,
chain_id,
database,
LimitedCostTracker::new_free(),
epoch_id,
Expand All @@ -600,12 +616,13 @@ impl<'a> OwnedEnvironment<'a> {

pub fn new_cost_limited(
mainnet: bool,
chain_id: u32,
database: ClarityDatabase<'a>,
cost_tracker: LimitedCostTracker,
epoch_id: StacksEpochId,
) -> OwnedEnvironment<'a> {
OwnedEnvironment {
context: GlobalContext::new(mainnet, database, cost_tracker, epoch_id),
context: GlobalContext::new(mainnet, chain_id, database, cost_tracker, epoch_id),
default_contract: ContractContext::new(
QualifiedContractIdentifier::transient(),
ClarityVersion::Clarity1,
Expand Down Expand Up @@ -1426,6 +1443,7 @@ impl<'a> GlobalContext<'a> {
// Instantiate a new Global Context
pub fn new(
mainnet: bool,
chain_id: u32,
database: ClarityDatabase,
cost_track: LimitedCostTracker,
epoch_id: StacksEpochId,
Expand All @@ -1438,6 +1456,7 @@ impl<'a> GlobalContext<'a> {
event_batches: Vec::new(),
mainnet,
epoch_id,
chain_id,
coverage_reporting: None,
}
}
Expand Down
26 changes: 23 additions & 3 deletions clarity/src/vm/costs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::vm::types::{
TypeSignature, NONE,
};
use crate::vm::{ast, eval_all, ClarityName, SymbolicExpression, Value};
use stacks_common::consts::{CHAIN_ID_MAINNET, CHAIN_ID_TESTNET};
obycode marked this conversation as resolved.
Show resolved Hide resolved
use stacks_common::types::StacksEpochId;

pub mod constants;
Expand Down Expand Up @@ -241,6 +242,7 @@ pub struct TrackerData {
/// evaluated, so no epoch identifier is necessary.
epoch: StacksEpochId,
mainnet: bool,
chain_id: u32,
}

#[derive(Clone)]
Expand Down Expand Up @@ -623,6 +625,7 @@ fn load_cost_functions(
impl LimitedCostTracker {
pub fn new(
mainnet: bool,
chain_id: u32,
limit: ExecutionCost,
clarity_db: &mut ClarityDatabase,
epoch: StacksEpochId,
Expand All @@ -637,6 +640,7 @@ impl LimitedCostTracker {
memory: 0,
epoch,
mainnet,
chain_id,
};
assert!(clarity_db.is_stack_empty());
cost_tracker.load_costs(clarity_db, true)?;
Expand All @@ -645,6 +649,7 @@ impl LimitedCostTracker {

pub fn new_mid_block(
mainnet: bool,
chain_id: u32,
limit: ExecutionCost,
clarity_db: &mut ClarityDatabase,
epoch: StacksEpochId,
Expand All @@ -659,6 +664,7 @@ impl LimitedCostTracker {
memory: 0,
epoch,
mainnet,
chain_id,
};
cost_tracker.load_costs(clarity_db, false)?;
Ok(Self::Limited(cost_tracker))
Expand All @@ -670,8 +676,16 @@ impl LimitedCostTracker {
epoch: StacksEpochId,
use_mainnet: bool,
) -> Result<LimitedCostTracker> {
use crate::vm::tests::test_only_mainnet_to_chain_id;
let chain_id = test_only_mainnet_to_chain_id(use_mainnet);
assert!(clarity_db.is_stack_empty());
LimitedCostTracker::new(use_mainnet, ExecutionCost::max_value(), clarity_db, epoch)
LimitedCostTracker::new(
use_mainnet,
chain_id,
ExecutionCost::max_value(),
clarity_db,
epoch,
)
}

pub fn new_free() -> LimitedCostTracker {
Expand Down Expand Up @@ -840,10 +854,16 @@ fn compute_cost(
eval_in_epoch: StacksEpochId,
) -> Result<ExecutionCost> {
let mainnet = cost_tracker.mainnet;
let chain_id = cost_tracker.chain_id;
let mut null_store = NullBackingStore::new();
let conn = null_store.as_clarity_db();
let mut global_context =
GlobalContext::new(mainnet, conn, LimitedCostTracker::new_free(), eval_in_epoch);
let mut global_context = GlobalContext::new(
mainnet,
chain_id,
conn,
LimitedCostTracker::new_free(),
eval_in_epoch,
);

let cost_contract = cost_tracker
.cost_contracts
Expand Down
Loading