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

fix(publisher): Include transaction_ids in blocks #324

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
5 changes: 3 additions & 2 deletions benches/nats-publisher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ async fn main() -> anyhow::Result<()> {
for height in 0..*last_height {
let height = height.into();
let block = block_helper.find_by_height(height);
let block = Block::new(&block, Consensus::default());
let block =
Block::new(&block, Consensus::default(), Vec::new());

block_helper.publish(&block).await?;
// for (index, tx) in block.transactions().iter().enumerate() {
Expand All @@ -65,7 +66,7 @@ async fn main() -> anyhow::Result<()> {
while let Ok(result) = subscription.recv().await {
let result = &**result;
let block = &result.sealed_block.entity;
let block = Block::new(block, Consensus::default());
let block = Block::new(block, Consensus::default(), Vec::new());

block_helper.publish(&block).await?;
// for (index, tx) in block.transactions().iter().enumerate() {
Expand Down
4 changes: 2 additions & 2 deletions crates/fuel-streams-core/src/blocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mod tests {
header: header.clone(),
height: 42,
id: Default::default(),
transactions: vec![], // Always empty for now
transaction_ids: vec![],
version: BlockVersion::V1,
};

Expand Down Expand Up @@ -76,7 +76,7 @@ mod tests {
},
"height": 42,
"id": "0000000000000000000000000000000000000000000000000000000000000000",
"transactions": [],
"transactionIds": [],
"version": "V1"
});

Expand Down
7 changes: 4 additions & 3 deletions crates/fuel-streams-core/src/blocks/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ pub struct Block {
pub header: BlockHeader,
pub height: u32,
pub id: FuelCoreBlockId,
pub transactions: Vec<Transaction>,
pub transaction_ids: Vec<Bytes32>,
pub version: BlockVersion,
}

impl Block {
pub fn new(
block: &fuel_core_types::blockchain::block::Block,
consensus: Consensus,
transaction_ids: Vec<Bytes32>,
) -> Self {
let header: BlockHeader = block.header().into();
let height = header.height;
Expand All @@ -32,7 +33,7 @@ impl Block {
header,
height,
id,
transactions: Vec::new(),
transaction_ids,
version,
}
}
Expand Down Expand Up @@ -187,6 +188,6 @@ impl MockBlock {
.collect::<Vec<_>>();
*block.transactions_mut() = txs;

Block::new(&block, Consensus::default())
Block::new(&block, Consensus::default(), Vec::new())
}
}
6 changes: 6 additions & 0 deletions crates/fuel-streams-publisher/src/publisher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ impl Publisher {
let block_producer = Arc::new(block_producer.clone());
let block_height = block.header().consensus().height;
let txs = block.transactions();
let transaction_ids = txs
.iter()
.map(|tx| tx.id(&chain_id).into())
.collect::<Vec<Bytes32>>();

let consensus: Consensus =
self.fuel_core.get_consensus(&block_height)?.into();

Expand Down Expand Up @@ -239,6 +244,7 @@ impl Publisher {
block,
block_stream,
opts,
transaction_ids,
)))
.collect::<FuturesUnordered<_>>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ pub fn publish_task(
block: &FuelCoreBlock<FuelCoreTransaction>,
stream: Arc<Stream<Block>>,
opts: &Arc<PublishOpts>,
transaction_ids: Vec<Bytes32>,
) -> JoinHandle<anyhow::Result<()>> {
let block_height = (*opts.block_height).clone();
let block_producer = (*opts.block_producer).clone();
let consensus = (*opts.consensus).clone();

let block = Block::new(block, consensus);
let block = Block::new(block, consensus, transaction_ids);
let packet = PublishPacket::new(
block,
BlocksSubject {
Expand Down
Loading