From b5dd75215632b8ad99b2e4e4088f166baa156c93 Mon Sep 17 00:00:00 2001 From: Mihir Wadekar Date: Tue, 6 Jun 2023 21:05:11 -0700 Subject: [PATCH 1/3] Added extra data to the block collector --- .../src/collectors/block_collector.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/artemis-core/src/collectors/block_collector.rs b/crates/artemis-core/src/collectors/block_collector.rs index 5b71642..8f65444 100644 --- a/crates/artemis-core/src/collectors/block_collector.rs +++ b/crates/artemis-core/src/collectors/block_collector.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use ethers::{ prelude::Middleware, providers::PubsubClient, - types::{H256, U64}, + types::{H256, U64, U256, Bytes}, }; use std::sync::Arc; use tokio_stream::StreamExt; @@ -20,6 +20,10 @@ pub struct BlockCollector { pub struct NewBlock { pub hash: H256, pub number: U64, + pub gas_used: U256, + pub timestamp: U256, + pub extra_data: Bytes, + pub base_fee_per_gas: U256 } impl BlockCollector { @@ -40,7 +44,14 @@ where async fn get_event_stream(&self) -> Result> { let stream = self.provider.subscribe_blocks().await?; let stream = stream.filter_map(|block| match block.hash { - Some(hash) => block.number.map(|number| NewBlock { hash, number }), + Some(hash) => { + let gas_used = block.gas_used; + let timestamp = block.timestamp; + let extra_data = block.extra_data; + let base_fee_per_gas = match block.base_fee_per_gas { Some(base_fee_per_gas) => base_fee_per_gas, None => U256::from(0)}; + + block.number.map(|number| NewBlock { hash, number, gas_used, timestamp, extra_data, base_fee_per_gas}) + }, None => None, }); Ok(Box::pin(stream)) From d63069b17cb6754e4a094606ab720d2b02a2ba0a Mon Sep 17 00:00:00 2001 From: Mihir Wadekar Date: Tue, 6 Jun 2023 21:13:59 -0700 Subject: [PATCH 2/3] Added some more data fields for block collector --- .../src/collectors/block_collector.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/artemis-core/src/collectors/block_collector.rs b/crates/artemis-core/src/collectors/block_collector.rs index 5b71642..8f65444 100644 --- a/crates/artemis-core/src/collectors/block_collector.rs +++ b/crates/artemis-core/src/collectors/block_collector.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use ethers::{ prelude::Middleware, providers::PubsubClient, - types::{H256, U64}, + types::{H256, U64, U256, Bytes}, }; use std::sync::Arc; use tokio_stream::StreamExt; @@ -20,6 +20,10 @@ pub struct BlockCollector { pub struct NewBlock { pub hash: H256, pub number: U64, + pub gas_used: U256, + pub timestamp: U256, + pub extra_data: Bytes, + pub base_fee_per_gas: U256 } impl BlockCollector { @@ -40,7 +44,14 @@ where async fn get_event_stream(&self) -> Result> { let stream = self.provider.subscribe_blocks().await?; let stream = stream.filter_map(|block| match block.hash { - Some(hash) => block.number.map(|number| NewBlock { hash, number }), + Some(hash) => { + let gas_used = block.gas_used; + let timestamp = block.timestamp; + let extra_data = block.extra_data; + let base_fee_per_gas = match block.base_fee_per_gas { Some(base_fee_per_gas) => base_fee_per_gas, None => U256::from(0)}; + + block.number.map(|number| NewBlock { hash, number, gas_used, timestamp, extra_data, base_fee_per_gas}) + }, None => None, }); Ok(Box::pin(stream)) From c8fd4e0bfdf934bfda572bc30d9c7d26d6ba2df2 Mon Sep 17 00:00:00 2001 From: Mihir Wadekar Date: Thu, 8 Jun 2023 02:33:33 -0700 Subject: [PATCH 3/3] Added block property to NewBlock, removed others. --- .../src/collectors/block_collector.rs | 23 ++++--------------- crates/artemis-core/tests/main.rs | 2 +- .../opensea-sudo-arb/src/strategy.rs | 12 +++++++--- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/crates/artemis-core/src/collectors/block_collector.rs b/crates/artemis-core/src/collectors/block_collector.rs index 8f65444..e94968a 100644 --- a/crates/artemis-core/src/collectors/block_collector.rs +++ b/crates/artemis-core/src/collectors/block_collector.rs @@ -4,13 +4,13 @@ use async_trait::async_trait; use ethers::{ prelude::Middleware, providers::PubsubClient, - types::{H256, U64, U256, Bytes}, + types::{Block, TxHash}, }; use std::sync::Arc; use tokio_stream::StreamExt; /// A collector that listens for new blocks, and generates a stream of -/// [events](NewBlock) which contain the block number and hash. +/// [events](NewBlock) which contain the entire block pub struct BlockCollector { provider: Arc, } @@ -18,12 +18,7 @@ pub struct BlockCollector { /// A new block event, containing the block number and hash. #[derive(Debug, Clone)] pub struct NewBlock { - pub hash: H256, - pub number: U64, - pub gas_used: U256, - pub timestamp: U256, - pub extra_data: Bytes, - pub base_fee_per_gas: U256 + pub block: Block, } impl BlockCollector { @@ -43,17 +38,7 @@ where { async fn get_event_stream(&self) -> Result> { let stream = self.provider.subscribe_blocks().await?; - let stream = stream.filter_map(|block| match block.hash { - Some(hash) => { - let gas_used = block.gas_used; - let timestamp = block.timestamp; - let extra_data = block.extra_data; - let base_fee_per_gas = match block.base_fee_per_gas { Some(base_fee_per_gas) => base_fee_per_gas, None => U256::from(0)}; - - block.number.map(|number| NewBlock { hash, number, gas_used, timestamp, extra_data, base_fee_per_gas}) - }, - None => None, - }); + let stream = stream.filter_map(|block| Some(NewBlock { block })); Ok(Box::pin(stream)) } } diff --git a/crates/artemis-core/tests/main.rs b/crates/artemis-core/tests/main.rs index 52fbe47..bb55ffe 100644 --- a/crates/artemis-core/tests/main.rs +++ b/crates/artemis-core/tests/main.rs @@ -35,7 +35,7 @@ async fn test_block_collector_sends_blocks() { .await .unwrap() .unwrap(); - assert_eq!(block_a.hash, block_b.hash.unwrap()); + assert_eq!(block_a.block.hash.unwrap(), block_b.hash.unwrap()); } /// Test that mempool collector correctly emits blocks. diff --git a/crates/strategies/opensea-sudo-arb/src/strategy.rs b/crates/strategies/opensea-sudo-arb/src/strategy.rs index 87d5ff5..585b201 100644 --- a/crates/strategies/opensea-sudo-arb/src/strategy.rs +++ b/crates/strategies/opensea-sudo-arb/src/strategy.rs @@ -153,14 +153,20 @@ impl OpenseaSudoArb { /// Process new block events, updating the internal state. async fn process_new_block_event(&mut self, event: NewBlock) -> Result<()> { - info!("processing new block {}", event.number); + info!("processing new block {}", event.block.number.unwrap()); // Find new pools tthat were created in the last block. let new_pools = self - .get_new_pools(event.number.as_u64(), event.number.as_u64()) + .get_new_pools( + event.block.number.unwrap().as_u64(), + event.block.number.unwrap().as_u64(), + ) .await?; // Find existing pools that were touched in the last block. let touched_pools = self - .get_touched_pools(event.number.as_u64(), event.number.as_u64()) + .get_touched_pools( + event.block.number.unwrap().as_u64(), + event.block.number.unwrap().as_u64(), + ) .await?; // Get quotes for all new and touched pools and update state. let quotes = self