Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Sep 27, 2023
1 parent 4248263 commit 1d3e9b7
Show file tree
Hide file tree
Showing 18 changed files with 1,122 additions and 363 deletions.
420 changes: 265 additions & 155 deletions dan_layer/consensus/src/hotstuff/on_receive_proposal.rs

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions dan_layer/consensus_tests/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,12 @@ async fn multi_shard_propose_blocks_with_new_transactions_until_all_committed()
async fn foreign_shard_decides_to_abort() {
setup_logger();
let mut test = Test::builder()
.add_committee(0, vec!["1", "3", "4"])
.add_committee(1, vec!["2", "5", "6"])
.debug_sql("/tmp/test{}.db")
.disable_timeout()
.add_committee(0, vec!["1"])
.add_committee(1, vec!["2"])
// .add_committee(0, vec!["1", "3", "4"])
// .add_committee(1, vec!["2", "5", "6"])
.start()
.await;

Expand Down Expand Up @@ -380,7 +384,7 @@ async fn leader_failure_node_goes_down() {
break;
}

if committed_height > NodeHeight(20) {
if committed_height > NodeHeight(40) {
panic!("Not all transaction committed after {} blocks", committed_height);
}
}
Expand Down
24 changes: 17 additions & 7 deletions dan_layer/consensus_tests/src/support/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct Test {
_leader_strategy: RoundRobinLeaderStrategy,
epoch_manager: TestEpochManager,
shutdown: Shutdown,
timeout: Duration,
timeout: Option<Duration>,
}

impl Test {
Expand Down Expand Up @@ -74,9 +74,13 @@ impl Test {

pub async fn on_block_committed(&mut self) -> (BlockId, NodeHeight) {
loop {
let event = timeout(self.timeout, self.on_hotstuff_event())
.await
.unwrap_or_else(|_| panic!("Timeout waiting for Hotstuff event"));
let event = if let Some(timeout) = self.timeout {
tokio::time::timeout(timeout, self.on_hotstuff_event())
.await
.unwrap_or_else(|_| panic!("Timeout waiting for Hotstuff event"))
} else {
self.on_hotstuff_event().await
};
match event {
HotstuffEvent::BlockCommitted { block_id, height } => return (block_id, height),
HotstuffEvent::Failure { message } => panic!("Consensus failure: {}", message),
Expand Down Expand Up @@ -280,7 +284,7 @@ impl Test {
pub struct TestBuilder {
committees: HashMap<ShardBucket, Committee<TestAddress>>,
sql_address: String,
timeout: Duration,
timeout: Option<Duration>,
debug_sql_file: Option<String>,
}

Expand All @@ -289,11 +293,17 @@ impl TestBuilder {
Self {
committees: HashMap::new(),
sql_address: ":memory:".to_string(),
timeout: Duration::from_secs(10),
timeout: Some(Duration::from_secs(10)),
debug_sql_file: None,
}
}

#[allow(dead_code)]
pub fn disable_timeout(&mut self) -> &mut Self {
self.timeout = None;
self
}

#[allow(dead_code)]
pub fn debug_sql<P: Into<String>>(&mut self, path: P) -> &mut Self {
self.debug_sql_file = Some(path.into());
Expand All @@ -307,7 +317,7 @@ impl TestBuilder {
}

pub fn with_test_timeout(&mut self, timeout: Duration) -> &mut Self {
self.timeout = timeout;
self.timeout = Some(timeout);
self
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ create table blocks
(
id integer not null primary key AUTOINCREMENT,
block_id text not NULL,
parent_block_id text NULL,
parent_block_id text not NULL,
height bigint not NULL,
epoch bigint not NULL,
proposed_by text not NULL,
Expand Down Expand Up @@ -159,19 +159,22 @@ create table transaction_pool
create unique index transaction_pool_uniq_idx_transaction_id on transaction_pool (transaction_id);
create index transaction_pool_idx_is_ready on transaction_pool (is_ready);

create table transaction_pool_status
create table transaction_pool_state_updates
(
id integer not null primary key AUTOINCREMENT,
block_id text not null,
block_height bigint not null,
transaction_id text not null,
stage text not null,
is_ready boolean not null,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
id integer not null primary key AUTOINCREMENT,
block_id text not null,
block_height bigint not null,
transaction_id text not null,
stage text not null,
evidence text not null,
is_ready boolean not null,
local_decision text not null,
remote_decision text null,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (block_id) REFERENCES blocks (block_id),
FOREIGN KEY (transaction_id) REFERENCES transactions (transaction_id)
);
create index transaction_pool_idx_block_id_transaction_id on transaction_pool_status (block_id, transaction_id);
create unique index transaction_pool_uniq_block_id_transaction_id on transaction_pool_state_updates (block_id, transaction_id);

create table locked_outputs
(
Expand Down Expand Up @@ -214,3 +217,66 @@ CREATE TABLE missing_transactions
is_awaiting_execution boolean not NULL,
created_at timestamp not NULL DEFAULT CURRENT_TIMESTAMP
);


-- Debug Triggers
CREATE TABLE transaction_pool_history
(
history_id INTEGER PRIMARY KEY,
id integer not null,
transaction_id text not null,
original_decision text not null,
local_decision text null,
remote_decision text null,
evidence text not null,
transaction_fee bigint not null,
leader_fee bigint not null,
stage text not null,
new_stage text not null,
pending_stage text null,
new_pending_stage text null,
is_ready boolean not null,
new_is_ready boolean not null,
updated_at timestamp NOT NULL,
created_at timestamp NOT NULL,
change_time DATETIME DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW'))
);

CREATE TRIGGER copy_transaction_pool_history
AFTER UPDATE
ON transaction_pool
FOR EACH ROW
BEGIN
INSERT INTO transaction_pool_history (id,
transaction_id,
original_decision,
local_decision,
remote_decision,
evidence,
transaction_fee,
leader_fee,
stage,
new_stage,
pending_stage,
new_pending_stage,
is_ready,
new_is_ready,
updated_at,
created_at)
VALUES (OLD.id,
OLD.transaction_id,
OLD.original_decision,
OLD.local_decision,
OLD.remote_decision,
OLD.evidence,
OLD.transaction_fee,
OLD.leader_fee,
OLD.stage,
NEW.stage,
OLD.pending_stage,
NEW.pending_stage,
OLD.is_ready,
NEW.is_ready,
OLD.updated_at,
OLD.created_at);
END;
Loading

0 comments on commit 1d3e9b7

Please sign in to comment.