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: revisit fork handling #429

Merged
merged 61 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
aed09c4
feat: implementation drafted, start test suite
Jun 24, 2022
67b9deb
test: vector_002 passing
Jun 24, 2022
49cefa4
test: vector_003 passing
Jun 24, 2022
0eaff03
test: vector_004 passing
Jun 24, 2022
3d27d26
test: vector_005 passing
Jun 24, 2022
9a8114d
test: vector_006 passing
Jun 24, 2022
87710c0
test: vector_007 passing
Jun 24, 2022
10dbb3c
test: vector_008 passing
Jun 24, 2022
c35f941
test: vector_009 passing
Jun 24, 2022
6cbbc08
test: vector_010 passing
Jun 24, 2022
1c0ea1d
test: vector_011 passing
Jun 24, 2022
d0f7959
test: vector_012 passing
Jun 24, 2022
025acd9
test: vector_013 passing
Jun 24, 2022
ca78450
test: vector_014 passing
Jun 24, 2022
2e298d5
test: vector_015 passing
Jun 24, 2022
7049aac
test: vector_016 passing
Jun 24, 2022
7a5a5e6
test: vector_017 passing
Jun 24, 2022
82cf5ca
test: vector_018 passing
Jun 24, 2022
34486a9
test: vector_019 passing
Jun 24, 2022
5c5763a
test: vector_020 passing
Jun 24, 2022
fc17372
test: vector_021 passing
Jun 27, 2022
303a074
test: vector_022 passing
Jun 27, 2022
d00131a
test: vector_023 passing
Jun 27, 2022
baf8874
test: vector_024 passing
Jun 27, 2022
60af9bf
test: vector_025 passing
Jun 27, 2022
b3495ac
test: vector_026 passing
Jun 27, 2022
1125dbf
test: vector_027 passing
Jun 27, 2022
18d5a1c
test: vector_028 passing
Jun 27, 2022
460404c
test: vector_029 passing
Jun 27, 2022
1e0e27b
test: vector_030 passing
Jun 27, 2022
bd5e29a
test: vector_031 passing
Jun 27, 2022
fe131a0
test: vector_032 passing
Jun 27, 2022
7bdacfa
test: vector_033 passing
Jun 27, 2022
fa0b45b
test: vector_034 passing
Jun 27, 2022
543150c
test: vector_035 passing
Jun 27, 2022
13097c2
test: vector_036 passing
Jun 27, 2022
70afea2
test: vector_037 passing
Jun 27, 2022
fb6bd74
test: vector_038 passing
Jun 28, 2022
38fb81a
test: vector_038 passing
Jun 28, 2022
34da9b6
test: vector_040 passing
Jun 28, 2022
825df8c
fix: build
Jun 28, 2022
cd843b8
test: fix vector_032
Jun 28, 2022
f02f818
feat: introduce expire_after_occurrence + unit tests
Jun 28, 2022
eaabf1c
feat: prepare support for microblocks
Jul 1, 2022
6899c84
test: vector_042 passing
Jul 5, 2022
ed5b43a
test: vector_043 passing
Jul 5, 2022
e02c828
test: vector_044 passing
Jul 5, 2022
fcf176a
test: vector_045 passing
Jul 5, 2022
a4807c0
test: vector_046 passing
Jul 5, 2022
0b27d02
test: vector_047 passing
Jul 5, 2022
a356926
test: vector_048 passing
Jul 6, 2022
d6e157d
test: vector_049 passing
Jul 6, 2022
c9bf2da
feat: add structured logs to oreo
Jul 6, 2022
53c36fc
feat: return confirmed_blocks
Jul 6, 2022
5f7e47d
feat: evaluate chainhooks on all kind of chain events
Jul 7, 2022
54f49b1
feat: bitcoin feature parity
Jul 7, 2022
9d711f5
fix: cascade changes
Jul 7, 2022
8a1519b
fix: cascade changes in node-binding
Jul 7, 2022
e72c9ac
fix: handle PR review
Jul 8, 2022
6931ee6
chore: cargo fmt
Jul 8, 2022
aa99c87
fix: broken build
Jul 8, 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
38 changes: 38 additions & 0 deletions Cargo.lock

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

9 changes: 6 additions & 3 deletions node-bindings/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const {
stacksDevnetWaitForBitcoinBlock,
stacksDevnetGetStacksNodeUrl,
} = require("../native/index.node");
import { Block } from "@hirosystems/orchestra-types";
import {
BitcoinChainUpdate,
StacksChainUpdate,
} from "@hirosystems/orchestra-types";
export * from "@hirosystems/orchestra-types";

/**
Expand Down Expand Up @@ -347,15 +350,15 @@ export class StacksDevnetOrchestrator {
* @summary Wait for the next Stacks block
* @memberof StacksDevnetOrchestrator
*/
waitForStacksBlock(): Block {
waitForStacksBlock(): StacksChainUpdate {
return stacksDevnetWaitForStacksBlock.call(this.handle);
}

/**
* @summary Wait for the next Bitcoin block
* @memberof StacksDevnetOrchestrator
*/
waitForBitcoinBlock(): Block {
waitForBitcoinBlock(): BitcoinChainUpdate {
return stacksDevnetWaitForBitcoinBlock.call(this.handle);
}

Expand Down
16 changes: 8 additions & 8 deletions node-bindings/package-lock.json

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

2 changes: 1 addition & 1 deletion node-bindings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"version": "npm run build-release"
},
"dependencies": {
"@hirosystems/orchestra-types": "^1.0.1-beta.1",
"@hirosystems/orchestra-types": "^1.0.1-beta.3",
"@mapbox/node-pre-gyp": "^1.0.8",
"neon-cli": "^0.9.1",
"node-pre-gyp-github": "^1.4.3",
Expand Down
23 changes: 12 additions & 11 deletions node-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use clarinet_files::{
use clarinet_lib::deployments;
use clarinet_lib::integrate::{self, DevnetEvent, DevnetOrchestrator};
use orchestra_types::{
BitcoinBlockData, BitcoinChainEvent, ChainUpdatedWithBlockData, StacksChainEvent, StacksNetwork,
BitcoinChainEvent, BitcoinChainUpdatedWithBlocksData, StacksChainEvent,
StacksChainUpdatedWithBlocksData, StacksNetwork,
};

use core::panic;
Expand All @@ -27,8 +28,8 @@ type DevnetCallback = Box<dyn FnOnce(&Channel) + Send>;

struct StacksDevnet {
tx: mpsc::Sender<DevnetCommand>,
bitcoin_block_rx: mpsc::Receiver<BitcoinBlockData>,
stacks_block_rx: mpsc::Receiver<ChainUpdatedWithBlockData>,
bitcoin_block_rx: mpsc::Receiver<BitcoinChainUpdatedWithBlocksData>,
stacks_block_rx: mpsc::Receiver<StacksChainUpdatedWithBlocksData>,
node_url: String,
}

Expand Down Expand Up @@ -115,15 +116,15 @@ impl StacksDevnet {
while let Ok(ref event) = devnet_rx.recv() {
match event {
DevnetEvent::BitcoinChainEvent(
BitcoinChainEvent::ChainUpdatedWithBlock(block),
BitcoinChainEvent::ChainUpdatedWithBlocks(block),
) => {
bitcoin_block_tx
.send(block.clone())
.expect("Unable to transmit bitcoin block");
}
DevnetEvent::StacksChainEvent(StacksChainEvent::ChainUpdatedWithBlock(
block,
)) => {
DevnetEvent::StacksChainEvent(
StacksChainEvent::ChainUpdatedWithBlocks(block),
) => {
stacks_block_tx
.send(block.clone())
.expect("Unable to transmit stacks block");
Expand Down Expand Up @@ -560,14 +561,14 @@ impl StacksDevnet {
.this()
.downcast_or_throw::<JsBox<StacksDevnet>, _>(&mut cx)?;

let block = match devnet.stacks_block_rx.recv() {
Ok(obj) => obj.new_block,
let blocks = match devnet.stacks_block_rx.recv() {
Ok(obj) => obj,
Err(err) => panic!("{:?}", err),
};

let js_block = serde::to_value(&mut cx, &block).expect("Unable to serialize block");
let js_blocks = serde::to_value(&mut cx, &blocks).expect("Unable to serialize block");

Ok(js_block)
Ok(js_blocks)
}

fn js_on_bitcoin_block(mut cx: FunctionContext) -> JsResult<JsValue> {
Expand Down
3 changes: 3 additions & 0 deletions src/chainhooks/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct ChainhookSpecificationFile {
pub struct ChainhookNetworkSpecificationFile {
start_block: Option<u64>,
end_block: Option<u64>,
expire_after_occurrence: Option<u64>,
predicate: ChainhookPredicateFile,
action: HookActionFile,
oreo_url: String,
Expand Down Expand Up @@ -147,6 +148,7 @@ impl ChainhookSpecificationFile {
network: network.clone(),
start_block: network_spec.start_block,
end_block: network_spec.end_block,
expire_after_occurrence: network_spec.expire_after_occurrence,
predicate: network_spec.predicate.to_bitcoin_predicate()?,
action: network_spec.action.to_specifications()?,
})
Expand Down Expand Up @@ -174,6 +176,7 @@ impl ChainhookSpecificationFile {
network: network.clone(),
start_block: network_spec.start_block,
end_block: network_spec.end_block,
expire_after_occurrence: network_spec.expire_after_occurrence,
predicate: network_spec.predicate.to_stacks_predicate()?,
action: network_spec.action.to_specifications()?,
})
Expand Down
45 changes: 24 additions & 21 deletions src/integrate/chains_coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,15 @@ pub async fn start_chains_coordinator(
// Contextual shortcut: Devnet is an environment under control,
// with 1 miner. As such we will ignore Reorgs handling.
let (log, status) = match &chain_update {
BitcoinChainEvent::ChainUpdatedWithBlock(block) => {
let log =
format!("Bitcoin block #{} received", block.block_identifier.index);
let status = format!(
"mining blocks (chaintip = #{})",
block.block_identifier.index
);
BitcoinChainEvent::ChainUpdatedWithBlocks(event) => {
let tip = event.new_blocks.last().unwrap();
let log = format!("Bitcoin block #{} received", tip.block_identifier.index);
let status =
format!("mining blocks (chaintip = #{})", tip.block_identifier.index);
(log, status)
}
BitcoinChainEvent::ChainUpdatedWithReorg(_old_blocks, new_blocks) => {
let tip = new_blocks.last().unwrap();
BitcoinChainEvent::ChainUpdatedWithReorg(events) => {
let tip = events.blocks_to_apply.last().unwrap();
let log = format!(
"Bitcoin reorg received (new height: {})",
tip.block_identifier.index
Expand Down Expand Up @@ -275,13 +273,18 @@ pub async fn start_chains_coordinator(
});
}

let update = match &chain_event {
StacksChainEvent::ChainUpdatedWithBlock(block) => block.clone(),
StacksChainEvent::ChainUpdatedWithMicroblock(_) => {
let known_tip = match &chain_event {
StacksChainEvent::ChainUpdatedWithBlocks(block) => {
match block.new_blocks.last() {
Some(known_tip) => known_tip.clone(),
None => unreachable!(),
}
}
StacksChainEvent::ChainUpdatedWithMicroblocks(_) => {
continue;
// TODO(lgalabru): good enough for now - code path unreachable in the context of Devnet
}
StacksChainEvent::ChainUpdatedWithMicroblockReorg(_) => {
StacksChainEvent::ChainUpdatedWithMicroblocksReorg(_) => {
unreachable!() // TODO(lgalabru): good enough for now - code path unreachable in the context of Devnet
}
StacksChainEvent::ChainUpdatedWithReorg(_) => {
Expand All @@ -299,24 +302,24 @@ pub async fn start_chains_coordinator(
name: "stacks-node".into(),
comment: format!(
"mining blocks (chaintip = #{})",
update.new_block.block_identifier.index
known_tip.block.block_identifier.index
),
}));
let _ = devnet_event_tx.send(DevnetEvent::info(format!(
"Block #{} anchored in Bitcoin block #{} includes {} transactions",
update.new_block.block_identifier.index,
update
.new_block
known_tip.block.block_identifier.index,
known_tip
.block
.metadata
.bitcoin_anchor_block_identifier
.index,
update.new_block.transactions.len(),
known_tip.block.transactions.len(),
)));

let should_submit_pox_orders = update.new_block.metadata.pox_cycle_position
== (update.new_block.metadata.pox_cycle_length - 2);
let should_submit_pox_orders = known_tip.block.metadata.pox_cycle_position
== (known_tip.block.metadata.pox_cycle_length - 2);
if should_submit_pox_orders {
let bitcoin_block_height = update.new_block.block_identifier.index;
let bitcoin_block_height = known_tip.block.block_identifier.index;
let res = publish_stacking_orders(
&config.devnet_config,
&config.accounts,
Expand Down
9 changes: 5 additions & 4 deletions src/integrate/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ pub fn start_ui(
app.display_service_status_update(status);
}
DevnetEvent::StacksChainEvent(chain_event) => {
if let StacksChainEvent::ChainUpdatedWithBlock(update) = chain_event {
if let StacksChainEvent::ChainUpdatedWithBlocks(update) = chain_event {

let raw_txs = if app.mempool.items.is_empty() {
vec![]
} else {
update.new_block.transactions.iter().map(|tx| tx.metadata.raw_tx.as_str()).collect::<Vec<_>>()
update.new_blocks.iter().flat_map(|b| b.block.transactions.iter().map(|tx| tx.metadata.raw_tx.as_str())).collect::<Vec<_>>()
};

let mut indices_to_remove = vec![];
Expand All @@ -114,8 +114,9 @@ pub fn start_ui(
for i in indices_to_remove {
app.mempool.items.remove(i);
}

app.display_block(update.new_block);
for block_update in update.new_blocks.into_iter() {
app.display_block(block_update.block);
}
} else {
// TODO(lgalabru)
}
Expand Down
5 changes: 4 additions & 1 deletion vendor/orchestra-event-observer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ clap = { version = "3.1.6", features = ["derive"], optional = true }
clap_generate = { version = "3.0.3", optional = true }
toml = { version = "0.5.6", features = ["preserve_order"], optional = true }
ctrlc = { version = "3.2.2", optional = true }
slog = { version = "2.7.0" }
slog-json = { version = "2.6.1", optional = true }
slog-scope = { version = "4.4.0", optional = true }

[features]
default = ["cli"]
cli = ["clap", "clap_generate", "toml", "ctrlc"]
cli = ["clap", "clap_generate", "toml", "ctrlc", "slog-json", "slog-scope"]
Loading