Skip to content

Commit acea311

Browse files
authored
Merge branch 'develop' into test/scenario
2 parents 1c0dc20 + 31d048c commit acea311

File tree

17 files changed

+1287
-178
lines changed

17 files changed

+1287
-178
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ jobs:
9494
needs:
9595
- rustfmt
9696
- check-release
97+
secrets: inherit
9798
uses: ./.github/workflows/github-release.yml
9899
with:
99100
node_tag: ${{ needs.check-release.outputs.node_tag }}

.github/workflows/clarity-js-sdk-pr.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

.github/workflows/core-build-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Build the binaries
2525
id: build
2626
run: |
27-
cargo build
27+
cargo build --bin stacks-inspect
2828
- name: Dump constants JSON
2929
id: consts-dump
3030
run: cargo run --bin stacks-inspect -- dump-consts | tee out.json

.github/workflows/github-release.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ concurrency:
3838
run-name: ${{ inputs.node_tag || inputs.signer_tag }}
3939

4040
jobs:
41-
## This job's sole purpose is trigger a secondary approval outside of the matrix jobs below.
41+
## This job's sole purpose is trigger a secondary approval outside of the matrix jobs below.
4242
## - If this job isn't approved to run, then the subsequent jobs will also not run - for this reason, we always exit 0
43-
## - `andon-cord` requires the repo environment "Build Release", which will trigger a secondary approval step before running this workflow.
43+
## - `andon-cord` requires the repo environment "Build Release", which will trigger a secondary approval step before running this workflow.
4444
andon-cord:
4545
if: |
4646
inputs.node_tag != '' ||
@@ -65,6 +65,9 @@ jobs:
6565
runs-on: ubuntu-latest
6666
needs:
6767
- andon-cord
68+
permissions:
69+
id-token: write
70+
attestations: write
6871
strategy:
6972
## Run a maximum of 10 builds concurrently, using the matrix defined in inputs.arch
7073
max-parallel: 10
@@ -135,6 +138,10 @@ jobs:
135138
inputs.signer_tag != ''
136139
name: Docker Image (Binary)
137140
runs-on: ubuntu-latest
141+
environment: "Push to Docker"
142+
permissions:
143+
id-token: write
144+
attestations: write
138145
needs:
139146
- andon-cord
140147
- build-binaries
@@ -164,7 +171,6 @@ jobs:
164171
## Create the downstream PR for the release branch to master,develop
165172
create-pr:
166173
if: |
167-
!contains(github.ref, '-rc') &&
168174
(
169175
inputs.node_tag != '' ||
170176
inputs.signer_tag != ''

.github/workflows/image-build-source.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
runs-on: ubuntu-latest
2424
## Requires the repo environment "Push to Docker", which will trigger a secondary approval step before running this workflow.
2525
environment: "Push to Docker"
26+
permissions:
27+
id-token: write
28+
attestations: write
2629
steps:
2730
## Setup Docker for the builds
2831
- name: Docker setup
@@ -68,3 +71,22 @@ jobs:
6871
GIT_COMMIT=${{ env.GITHUB_SHA_SHORT }}
6972
TARGET_CPU=x86-64-v3
7073
push: ${{ env.DOCKER_PUSH }}
74+
75+
## Generate docker image attestation(s)
76+
- name: Generate artifact attestation (${{ github.event.repository.name }})
77+
id: attest_primary
78+
uses: actions/attest-build-provenance@c074443f1aee8d4aeeae555aebba3282517141b2 # v2.2.3
79+
with:
80+
subject-name: |
81+
index.docker.io/${{env.docker-org}}/${{ github.event.repository.name }}
82+
subject-digest: ${{ steps.docker_build.outputs.digest }}
83+
push-to-registry: true
84+
85+
- name: Generate artifact attestation (stacks-blockchain)
86+
id: attest_secondary
87+
uses: actions/attest-build-provenance@c074443f1aee8d4aeeae555aebba3282517141b2 # v2.2.3
88+
with:
89+
subject-name: |
90+
index.docker.io/${{env.docker-org}}/stacks-blockchain
91+
subject-digest: ${{ steps.docker_build.outputs.digest }}
92+
push-to-registry: true

libsigner/src/events.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,14 @@ pub enum SignerEvent<T: SignerEventTrait> {
192192
/// The `Vec<T>` will contain any signer messages made by the miner.
193193
MinerMessages(Vec<T>),
194194
/// The signer messages for other signers and miners to observe
195-
/// The u32 is the signer set to which the message belongs (either 0 or 1)
196-
SignerMessages(u32, Vec<T>),
195+
SignerMessages {
196+
/// The signer set to which the message belongs (either 0 or 1)
197+
signer_set: u32,
198+
/// Each message of type `T` is paired with the `StacksPublicKey` of the slot from which it was retreived
199+
messages: Vec<(StacksPublicKey, T)>,
200+
/// the time at which this event was received by the signer's event processor
201+
received_time: SystemTime,
202+
},
197203
/// A new block proposal validation response from the node
198204
BlockValidationResponse(BlockValidateResponse),
199205
/// Status endpoint request
@@ -518,6 +524,7 @@ impl<T: SignerEventTrait> TryFrom<StackerDBChunksEvent> for SignerEvent<T> {
518524
type Error = EventError;
519525

520526
fn try_from(event: StackerDBChunksEvent) -> Result<Self, Self::Error> {
527+
let received_time = SystemTime::now();
521528
let signer_event = if event.contract_id.name.as_str() == MINERS_NAME
522529
&& event.contract_id.is_boot()
523530
{
@@ -536,12 +543,21 @@ impl<T: SignerEventTrait> TryFrom<StackerDBChunksEvent> for SignerEvent<T> {
536543
return Err(EventError::UnrecognizedStackerDBContract(event.contract_id));
537544
};
538545
// signer-XXX-YYY boot contract
539-
let signer_messages: Vec<T> = event
546+
let messages: Vec<(StacksPublicKey, T)> = event
540547
.modified_slots
541548
.iter()
542-
.filter_map(|chunk| read_next::<T, _>(&mut &chunk.data[..]).ok())
549+
.filter_map(|chunk| {
550+
Some((
551+
chunk.recover_pk().ok()?,
552+
read_next::<T, _>(&mut &chunk.data[..]).ok()?,
553+
))
554+
})
543555
.collect();
544-
SignerEvent::SignerMessages(signer_set, signer_messages)
556+
SignerEvent::SignerMessages {
557+
signer_set,
558+
messages,
559+
received_time,
560+
}
545561
} else {
546562
return Err(EventError::UnrecognizedStackerDBContract(event.contract_id));
547563
};

libsigner/src/tests/mod.rs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ use std::fmt::Debug;
2020
use std::io::{Read, Write};
2121
use std::net::{SocketAddr, TcpStream, ToSocketAddrs};
2222
use std::sync::mpsc::{channel, Receiver, Sender};
23-
use std::time::Duration;
23+
use std::time::{Duration, SystemTime};
2424
use std::{mem, thread};
2525

2626
use blockstack_lib::chainstate::nakamoto::signer_set::NakamotoSigners;
2727
use blockstack_lib::chainstate::nakamoto::{NakamotoBlock, NakamotoBlockHeader};
2828
use blockstack_lib::chainstate::stacks::boot::SIGNERS_NAME;
2929
use blockstack_lib::chainstate::stacks::events::StackerDBChunksEvent;
3030
use blockstack_lib::util_lib::boot::boot_code_id;
31-
use clarity::types::chainstate::{ConsensusHash, StacksBlockId, TrieHash};
31+
use clarity::types::chainstate::{ConsensusHash, StacksBlockId, StacksPublicKey, TrieHash};
3232
use clarity::util::hash::Sha512Trunc256Sum;
3333
use clarity::util::secp256k1::MessageSignature;
3434
use clarity::vm::types::QualifiedContractIdentifier;
@@ -142,6 +142,13 @@ fn test_simple_signer() {
142142
chunks.push(chunk_event);
143143
}
144144

145+
chunks.sort_by(|ev1, ev2| {
146+
ev1.modified_slots[0]
147+
.slot_id
148+
.partial_cmp(&ev2.modified_slots[0].slot_id)
149+
.unwrap()
150+
});
151+
145152
let thread_chunks = chunks.clone();
146153

147154
// simulate a node that's trying to push data
@@ -177,23 +184,44 @@ fn test_simple_signer() {
177184
sleep_ms(5000);
178185
let accepted_events = running_signer.stop().unwrap();
179186

180-
chunks.sort_by(|ev1, ev2| {
181-
ev1.modified_slots[0]
182-
.slot_id
183-
.partial_cmp(&ev2.modified_slots[0].slot_id)
184-
.unwrap()
185-
});
186-
187187
let sent_events: Vec<SignerEvent<SignerMessage>> = chunks
188188
.iter()
189189
.map(|chunk| {
190190
let msg = chunk.modified_slots[0].data.clone();
191+
let pubkey = chunk.modified_slots[0]
192+
.recover_pk()
193+
.expect("Faield to recover public key of slot");
191194
let signer_message = read_next::<SignerMessage, _>(&mut &msg[..]).unwrap();
192-
SignerEvent::SignerMessages(0, vec![signer_message])
195+
SignerEvent::SignerMessages {
196+
signer_set: 0,
197+
messages: vec![(pubkey, signer_message)],
198+
received_time: SystemTime::now(),
199+
}
193200
})
194201
.collect();
195202

196-
assert_eq!(sent_events, accepted_events);
203+
for (sent_event, accepted_event) in sent_events.iter().zip(accepted_events.iter()) {
204+
let SignerEvent::SignerMessages {
205+
signer_set,
206+
messages,
207+
received_time,
208+
} = sent_event
209+
else {
210+
panic!("BUG: should not have sent anything but a signer message");
211+
};
212+
let SignerEvent::SignerMessages {
213+
signer_set: accepted_signer_set,
214+
messages: accepted_messages,
215+
received_time: accepted_time,
216+
} = accepted_event
217+
else {
218+
panic!("BUG: should not have accepted anything but a signer message");
219+
};
220+
221+
assert_eq!(signer_set, accepted_signer_set);
222+
assert_eq!(messages, accepted_messages);
223+
assert_ne!(received_time, accepted_time);
224+
}
197225
mock_stacks_node.join().unwrap();
198226
}
199227

libsigner/src/v0/messages.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
//! and the `SignerMessage` enum.
2525
2626
use std::fmt::{Debug, Display};
27+
use std::hash::{Hash, Hasher};
2728
use std::io::{Read, Write};
2829
use std::marker::PhantomData;
2930
use std::net::{SocketAddr, TcpListener, TcpStream};
@@ -573,7 +574,7 @@ pub enum StateMachineUpdateContent {
573574
}
574575

575576
/// Message for update the Signer State infos
576-
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
577+
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, Hash)]
577578
pub enum StateMachineUpdateMinerState {
578579
/// There is an active miner
579580
ActiveMiner {

0 commit comments

Comments
 (0)