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

Include block height in LedgerTxEvent::AppliedTx #64

Open
wants to merge 1 commit into
base: update_rocksdb
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 10 additions & 2 deletions spectrum-offchain-lm/src/event_sink/handlers/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,22 @@ where
{
async fn try_handle(&mut self, ev: LedgerTxEvent) -> Option<LedgerTxEvent> {
let res = match ev {
LedgerTxEvent::AppliedTx { tx, timestamp } => {
LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
} => {
let transitions = self.extract_transitions(tx.clone()).await;
let is_success = !transitions.is_empty();
for tr in transitions {
let _ = self.topic.feed(Confirmed(StateUpdate::Transition(tr))).await;
}
if is_success {
Some(LedgerTxEvent::AppliedTx { tx, timestamp })
Some(LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
})
} else {
None
}
Expand Down
12 changes: 10 additions & 2 deletions spectrum-offchain-lm/src/event_sink/handlers/funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ where
{
async fn try_handle(&mut self, ev: LedgerTxEvent) -> Option<LedgerTxEvent> {
let res = match ev {
LedgerTxEvent::AppliedTx { tx, timestamp } => {
LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
} => {
let mut is_success = false;
{
let repo = self.repo.lock().await;
Expand Down Expand Up @@ -60,7 +64,11 @@ where
if is_success {
None
} else {
Some(LedgerTxEvent::AppliedTx { tx, timestamp })
Some(LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
})
}
}
LedgerTxEvent::UnappliedTx(tx) => {
Expand Down
12 changes: 10 additions & 2 deletions spectrum-offchain-lm/src/event_sink/handlers/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ where
{
async fn try_handle(&mut self, ev: LedgerTxEvent) -> Option<LedgerTxEvent> {
match ev {
LedgerTxEvent::AppliedTx { tx, timestamp } => {
LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
} => {
let mut is_success = false;
for o in &tx.outputs {
if let Some(pool) = Pool::try_from_box(o.clone()) {
Expand All @@ -43,7 +47,11 @@ where
trace!(target: "offchain_lm", "New program parsed from applied tx");
None
} else {
Some(LedgerTxEvent::AppliedTx { tx, timestamp })
Some(LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
})
}
}
ev => Some(ev),
Expand Down
12 changes: 10 additions & 2 deletions spectrum-offchain-lm/src/event_sink/handlers/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ where
{
async fn try_handle(&mut self, ev: LedgerTxEvent) -> Option<LedgerTxEvent> {
match ev {
LedgerTxEvent::AppliedTx { tx, timestamp } => {
LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
} => {
let mut is_success = false;
for o in &tx.outputs {
if let Some(pool) = Pool::try_from_box(o.clone()) {
Expand All @@ -58,7 +62,11 @@ where
trace!(target: "offchain_lm", "New schedule parsed from applied tx");
None
} else {
Some(LedgerTxEvent::AppliedTx { tx, timestamp })
Some(LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
})
}
}
LedgerTxEvent::UnappliedTx(tx) => {
Expand Down
12 changes: 10 additions & 2 deletions spectrum-offchain/src/event_sink/handlers/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ where
{
async fn try_handle(&mut self, ev: LedgerTxEvent) -> Option<LedgerTxEvent> {
let res = match ev {
LedgerTxEvent::AppliedTx { tx, timestamp } => {
LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
} => {
let transitions =
extract_transitions(Arc::clone(&self.entities), &self.blacklisted_entities, tx.clone())
.await;
Expand All @@ -120,7 +124,11 @@ where
trace!(target: "offchain_lm", "[{}] entities parsed from applied tx", num_transitions);
None
} else {
Some(LedgerTxEvent::AppliedTx { tx, timestamp })
Some(LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
})
}
}
LedgerTxEvent::UnappliedTx(tx) => {
Expand Down
12 changes: 10 additions & 2 deletions spectrum-offchain/src/event_sink/handlers/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ where
{
async fn try_handle(&mut self, ev: LedgerTxEvent) -> Option<LedgerTxEvent> {
let res = match ev {
LedgerTxEvent::AppliedTx { tx, timestamp } => {
LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
} => {
let mut is_success = false;
for i in tx.clone().inputs {
let order_id = TOrd::TOrderId::from(i.box_id);
Expand Down Expand Up @@ -78,7 +82,11 @@ where
if is_success {
return None;
}
Some(LedgerTxEvent::AppliedTx { tx, timestamp })
Some(LedgerTxEvent::AppliedTx {
tx,
timestamp,
height,
})
}
LedgerTxEvent::UnappliedTx(tx) => {
let mut is_success = false;
Expand Down
1 change: 1 addition & 0 deletions spectrum-offchain/src/event_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn process_upgrade(upgr: ChainUpgrade) -> Vec<LedgerTxEvent> {
.map(|tx| LedgerTxEvent::AppliedTx {
tx,
timestamp: ts as i64,
height: blk.height,
})
.collect()
}
Expand Down
6 changes: 5 additions & 1 deletion spectrum-offchain/src/event_source/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use ergo_lib::chain::transaction::Transaction;
/// Possible events that can happen with transactions on-chain.
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum LedgerTxEvent {
AppliedTx { timestamp: i64, tx: Transaction },
AppliedTx {
timestamp: i64,
tx: Transaction,
height: u32,
},
UnappliedTx(Transaction),
}
Loading