Skip to content

Commit

Permalink
Merge branch 'develop' into feat/pox-4-stateful-property-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
moodmosaic committed Apr 23, 2024
2 parents 5679afa + d76fd81 commit b1d7d2e
Show file tree
Hide file tree
Showing 46 changed files with 7,333 additions and 2,554 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ The changelog for this release is a high-level summary of these SIPs.
### Added

- Added prometheus output for "transactions in last block" (#3138).
- Added envrionement variable STACKS_LOG_FORMAT_TIME to set the time format
- Added environment variable STACKS_LOG_FORMAT_TIME to set the time format
stacks-node uses for logging. (#3219)
Example: STACKS_LOG_FORMAT_TIME="%Y-%m-%d %H:%M:%S" cargo stacks-node
- Added mock-miner sample config (#3225)
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion clarity/src/vm/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,11 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> {
let contract = self
.global_context
.database
.get_contract(contract_identifier)?;
.get_contract(contract_identifier)
.or_else(|e| {
self.global_context.roll_back()?;
Err(e)
})?;

let result = {
let mut nested_env = Environment::new(
Expand Down
35 changes: 35 additions & 0 deletions clarity/src/vm/tests/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,3 +1147,38 @@ fn test_cc_trait_stack_depth(
RuntimeErrorType::MaxStackDepthReached.into()
);
}

#[apply(test_epochs)]
fn test_eval_with_non_existing_contract(
epoch: StacksEpochId,
mut env_factory: MemoryEnvironmentGenerator,
) {
let mut owned_env = env_factory.get_env(epoch);

let mut placeholder_context = ContractContext::new(
QualifiedContractIdentifier::transient(),
ClarityVersion::Clarity2,
);

let mut env = owned_env.get_exec_environment(
Some(get_principal().expect_principal().unwrap()),
None,
&mut placeholder_context,
);

let result = env.eval_read_only(
&QualifiedContractIdentifier::local("absent").unwrap(),
"(ok 0)",
);
assert_eq!(
result.as_ref().unwrap_err(),
&Error::Unchecked(CheckErrors::NoSuchContract(
QualifiedContractIdentifier::local("absent")
.unwrap()
.to_string()
))
);
drop(env);
owned_env.commit().unwrap();
assert!(owned_env.destruct().is_some());
}
6 changes: 4 additions & 2 deletions docs/mining.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Stacks tokens (STX) are mined by transferring BTC via PoX. To run as a miner,
you should make sure to add the following config fields to your config file:

```
```toml
[node]
# Run as a miner
miner = True
Expand All @@ -25,6 +25,8 @@ first_attempt_time_ms = 1000
subsequent_attempt_time_ms = 60000
# Time to spend mining a microblock, in milliseconds.
microblock_attempt_time_ms = 30000
# Time to spend mining a Nakamoto block, in milliseconds.
nakamoto_attempt_time_ms = 10000
```

You can verify that your node is operating as a miner by checking its log output
Expand All @@ -40,7 +42,7 @@ INFO [1630127492.062652] [testnet/stacks-node/src/run_loop/neon.rs:164] [main] U

Fee and cost estimators can be configured via the config section `[fee_estimation]`:

```
```toml
[fee_estimation]
cost_estimator = naive_pessimistic
fee_estimator = fuzzed_weighted_median_fee_rate
Expand Down
1 change: 1 addition & 0 deletions libsigner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tiny_http = "0.12"
wsts = { workspace = true }

[dev-dependencies]
mutants = "0.0.3"
rand_core = { workspace = true }
rand = { workspace = true }

Expand Down
31 changes: 29 additions & 2 deletions libsigner/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use blockstack_lib::net::api::postblock_proposal::{
BlockValidateReject, BlockValidateResponse, ValidateRejectCode,
};
use blockstack_lib::util_lib::boot::boot_code_id;
use clarity::util::retry::BoundReader;
use clarity::vm::types::serialization::SerializationError;
use clarity::vm::types::QualifiedContractIdentifier;
use hashbrown::{HashMap, HashSet};
Expand Down Expand Up @@ -94,14 +95,17 @@ MessageSlotID {
/// Transactions list for miners and signers to observe
Transactions = 11,
/// DKG Results
DkgResults = 12
DkgResults = 12,
/// Persisted encrypted signer state containing DKG shares
EncryptedSignerState = 13
});

define_u8_enum!(SignerMessageTypePrefix {
BlockResponse = 0,
Packet = 1,
Transactions = 2,
DkgResults = 3
DkgResults = 3,
EncryptedSignerState = 4
});

impl MessageSlotID {
Expand Down Expand Up @@ -136,12 +140,14 @@ impl TryFrom<u8> for SignerMessageTypePrefix {
}

impl From<&SignerMessage> for SignerMessageTypePrefix {
#[cfg_attr(test, mutants::skip)]
fn from(message: &SignerMessage) -> Self {
match message {
SignerMessage::Packet(_) => SignerMessageTypePrefix::Packet,
SignerMessage::BlockResponse(_) => SignerMessageTypePrefix::BlockResponse,
SignerMessage::Transactions(_) => SignerMessageTypePrefix::Transactions,
SignerMessage::DkgResults { .. } => SignerMessageTypePrefix::DkgResults,
SignerMessage::EncryptedSignerState(_) => SignerMessageTypePrefix::EncryptedSignerState,
}
}
}
Expand Down Expand Up @@ -234,9 +240,12 @@ pub enum SignerMessage {
/// The polynomial commits used to construct the aggregate key
party_polynomials: Vec<(u32, PolyCommitment)>,
},
/// The encrypted state of the signer to be persisted
EncryptedSignerState(Vec<u8>),
}

impl Debug for SignerMessage {
#[cfg_attr(test, mutants::skip)]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::BlockResponse(b) => Debug::fmt(b, f),
Expand All @@ -255,12 +264,16 @@ impl Debug for SignerMessage {
.field("party_polynomials", &party_polynomials)
.finish()
}
Self::EncryptedSignerState(s) => {
f.debug_tuple("EncryptedSignerState").field(s).finish()
}
}
}
}

impl SignerMessage {
/// Helper function to determine the slot ID for the provided stacker-db writer id
#[cfg_attr(test, mutants::skip)]
pub fn msg_id(&self) -> MessageSlotID {
match self {
Self::Packet(packet) => match packet.msg {
Expand All @@ -278,6 +291,7 @@ impl SignerMessage {
Self::BlockResponse(_) => MessageSlotID::BlockResponse,
Self::Transactions(_) => MessageSlotID::Transactions,
Self::DkgResults { .. } => MessageSlotID::DkgResults,
Self::EncryptedSignerState(_) => MessageSlotID::EncryptedSignerState,
}
}
}
Expand Down Expand Up @@ -345,10 +359,14 @@ impl StacksMessageCodec for SignerMessage {
party_polynomials.iter().map(|(a, b)| (a, b)),
)?;
}
SignerMessage::EncryptedSignerState(encrypted_state) => {
write_next(fd, encrypted_state)?;
}
};
Ok(())
}

#[cfg_attr(test, mutants::skip)]
fn consensus_deserialize<R: Read>(fd: &mut R) -> Result<Self, CodecError> {
let type_prefix_byte = read_next::<u8, _>(fd)?;
let type_prefix = SignerMessageTypePrefix::try_from(type_prefix_byte)?;
Expand Down Expand Up @@ -383,6 +401,15 @@ impl StacksMessageCodec for SignerMessage {
party_polynomials,
}
}
SignerMessageTypePrefix::EncryptedSignerState => {
// Typically the size of the signer state is much smaller, but in the fully degenerate case the size of the persisted state is
// 2800 * 32 * 4 + C for some small constant C.
// To have some margin, we're expanding the left term with an additional factor 4
let max_encrypted_state_size = 2800 * 32 * 4 * 4;
let mut bound_reader = BoundReader::from_reader(fd, max_encrypted_state_size);
let encrypted_state = read_next::<_, _>(&mut bound_reader)?;
SignerMessage::EncryptedSignerState(encrypted_state)
}
};
Ok(message)
}
Expand Down

0 comments on commit b1d7d2e

Please sign in to comment.