Skip to content

Commit 8f6af15

Browse files
committed
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into feat/signers-read-stackerdb
2 parents 9f26d4a + 34b97e1 commit 8f6af15

File tree

44 files changed

+2550
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2550
-299
lines changed

.cargo/config

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
stacks-node = "run --package stacks-node --"
33
fmt-stacks = "fmt -- --config group_imports=StdExternalCrate,imports_granularity=Module"
44

5-
# Default to `native`
6-
# This makes it slightly faster for running tests and locally built binaries.
7-
# This can cause trouble when building "portable" binaries, such as for docker,
8-
# so disable it with the "portable" feature.
9-
[target.'cfg(not(feature = "portable"))']
10-
rustflags = ["-Ctarget-cpu=native"]
5+
# Uncomment to improve performance slightly, at the cost of portability
6+
# * Note that native binaries may not run on CPUs that are different from the build machine
7+
# [build]
8+
# rustflags = ["-Ctarget-cpu=native"]
119

1210
# Needed by perf to generate flamegraphs.
1311
#[target.x86_64-unknown-linux-gnu]

.github/actions/dockerfiles/Dockerfile.debian-source

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RUN --mount=type=tmpfs,target=${BUILD_DIR} cp -R /src/. ${BUILD_DIR}/ \
1919
&& cd ${BUILD_DIR} \
2020
&& rustup target add ${TARGET} \
2121
&& rustup component add rustfmt \
22-
&& cargo build --features monitoring_prom,slog_json,portable --release --workspace --target ${TARGET} \
22+
&& cargo build --features monitoring_prom,slog_json --release --workspace --target ${TARGET} \
2323
&& mkdir -p /out \
2424
&& cp -R ${BUILD_DIR}/target/${TARGET}/release/. /out
2525

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ The changelog for this release is a high-level summary of these SIPs.
363363
### Added
364364

365365
- Added prometheus output for "transactions in last block" (#3138).
366-
- Added envrionement variable STACKS_LOG_FORMAT_TIME to set the time format
366+
- Added environment variable STACKS_LOG_FORMAT_TIME to set the time format
367367
stacks-node uses for logging. (#3219)
368368
Example: STACKS_LOG_FORMAT_TIME="%Y-%m-%d %H:%M:%S" cargo stacks-node
369369
- Added mock-miner sample config (#3225)

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN apk add --no-cache musl-dev
1212

1313
RUN mkdir /out
1414

15-
RUN cd testnet/stacks-node && cargo build --features monitoring_prom,slog_json,portable --release
15+
RUN cd testnet/stacks-node && cargo build --features monitoring_prom,slog_json --release
1616

1717
RUN cp target/release/stacks-node /out
1818

Dockerfile.debian

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ COPY . .
1010

1111
RUN mkdir /out
1212

13-
RUN cd testnet/stacks-node && cargo build --features monitoring_prom,slog_json,portable --release
13+
RUN cd testnet/stacks-node && cargo build --features monitoring_prom,slog_json --release
1414

1515
RUN cp target/release/stacks-node /out
1616

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ cargo build --release
4949
cargo build --profile release-lite
5050
```
5151

52+
_Note on building_: you may set `RUSTFLAGS` to build binaries for your native cpu:
53+
54+
```
55+
RUSTFLAGS="-Ctarget-cpu=native"
56+
```
57+
58+
or uncomment these lines in `./cargo/config`:
59+
60+
```
61+
# [build]
62+
# rustflags = ["-Ctarget-cpu=native"]
63+
```
64+
5265
## Testing
5366

5467
**Run the tests:**

libsigner/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ tiny_http = "0.12"
3333
wsts = { workspace = true }
3434

3535
[dev-dependencies]
36+
mutants = "0.0.3"
3637
rand_core = { workspace = true }
3738
rand = { workspace = true }
3839

libsigner/src/messages.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use blockstack_lib::net::api::postblock_proposal::{
3838
BlockValidateReject, BlockValidateResponse, ValidateRejectCode,
3939
};
4040
use blockstack_lib::util_lib::boot::boot_code_id;
41+
use clarity::util::retry::BoundReader;
4142
use clarity::vm::types::serialization::SerializationError;
4243
use clarity::vm::types::QualifiedContractIdentifier;
4344
use hashbrown::{HashMap, HashSet};
@@ -94,14 +95,17 @@ MessageSlotID {
9495
/// Transactions list for miners and signers to observe
9596
Transactions = 11,
9697
/// DKG Results
97-
DkgResults = 12
98+
DkgResults = 12,
99+
/// Persisted encrypted signer state containing DKG shares
100+
EncryptedSignerState = 13
98101
});
99102

100103
define_u8_enum!(SignerMessageTypePrefix {
101104
BlockResponse = 0,
102105
Packet = 1,
103106
Transactions = 2,
104-
DkgResults = 3
107+
DkgResults = 3,
108+
EncryptedSignerState = 4
105109
});
106110

107111
impl MessageSlotID {
@@ -136,12 +140,14 @@ impl TryFrom<u8> for SignerMessageTypePrefix {
136140
}
137141

138142
impl From<&SignerMessage> for SignerMessageTypePrefix {
143+
#[cfg_attr(test, mutants::skip)]
139144
fn from(message: &SignerMessage) -> Self {
140145
match message {
141146
SignerMessage::Packet(_) => SignerMessageTypePrefix::Packet,
142147
SignerMessage::BlockResponse(_) => SignerMessageTypePrefix::BlockResponse,
143148
SignerMessage::Transactions(_) => SignerMessageTypePrefix::Transactions,
144149
SignerMessage::DkgResults { .. } => SignerMessageTypePrefix::DkgResults,
150+
SignerMessage::EncryptedSignerState(_) => SignerMessageTypePrefix::EncryptedSignerState,
145151
}
146152
}
147153
}
@@ -234,9 +240,12 @@ pub enum SignerMessage {
234240
/// The polynomial commits used to construct the aggregate key
235241
party_polynomials: Vec<(u32, PolyCommitment)>,
236242
},
243+
/// The encrypted state of the signer to be persisted
244+
EncryptedSignerState(Vec<u8>),
237245
}
238246

239247
impl Debug for SignerMessage {
248+
#[cfg_attr(test, mutants::skip)]
240249
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
241250
match self {
242251
Self::BlockResponse(b) => Debug::fmt(b, f),
@@ -255,12 +264,16 @@ impl Debug for SignerMessage {
255264
.field("party_polynomials", &party_polynomials)
256265
.finish()
257266
}
267+
Self::EncryptedSignerState(s) => {
268+
f.debug_tuple("EncryptedSignerState").field(s).finish()
269+
}
258270
}
259271
}
260272
}
261273

262274
impl SignerMessage {
263275
/// Helper function to determine the slot ID for the provided stacker-db writer id
276+
#[cfg_attr(test, mutants::skip)]
264277
pub fn msg_id(&self) -> MessageSlotID {
265278
match self {
266279
Self::Packet(packet) => match packet.msg {
@@ -278,6 +291,7 @@ impl SignerMessage {
278291
Self::BlockResponse(_) => MessageSlotID::BlockResponse,
279292
Self::Transactions(_) => MessageSlotID::Transactions,
280293
Self::DkgResults { .. } => MessageSlotID::DkgResults,
294+
Self::EncryptedSignerState(_) => MessageSlotID::EncryptedSignerState,
281295
}
282296
}
283297
}
@@ -345,10 +359,14 @@ impl StacksMessageCodec for SignerMessage {
345359
party_polynomials.iter().map(|(a, b)| (a, b)),
346360
)?;
347361
}
362+
SignerMessage::EncryptedSignerState(encrypted_state) => {
363+
write_next(fd, encrypted_state)?;
364+
}
348365
};
349366
Ok(())
350367
}
351368

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

0 commit comments

Comments
 (0)