Skip to content

Commit 375d976

Browse files
authored
chore(repo): misc updates (#20)
As we're using nightly fmt we can add some nice directives on the rustfmt toml. Also updating the rust version and the org name. Closes ENG-666 https://www.youtube.com/watch?v=WxnN05vOuSM
1 parent 012b9c2 commit 375d976

File tree

11 files changed

+46
-94
lines changed

11 files changed

+46
-94
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ version = "0.1.1"
44
description = "Zenith Builder Example"
55

66
edition = "2021"
7-
rust-version = "1.81"
7+
rust-version = "1.82"
88
authors = ["init4"]
99
license = "Apache-2.0 OR MIT"
10-
homepage = "https://github.com/init4tt/zenith"
11-
repository = "https://github.com/init4tt/zenith"
10+
homepage = "https://github.com/init4tech/builder"
11+
repository = "https://github.com/init4tech/builder"
1212

1313
[lib]
1414
name = "builder"

bin/builder.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ async fn main() -> eyre::Result<()> {
1717
let provider = config.connect_provider().await?;
1818
let authenticator = Authenticator::new(&config);
1919

20-
tracing::debug!(
21-
rpc_url = config.host_rpc_url.as_ref(),
22-
"instantiated provider"
23-
);
20+
tracing::debug!(rpc_url = config.host_rpc_url.as_ref(), "instantiated provider");
2421

2522
let sequencer_signer = config.connect_sequencer_signer().await?;
2623
let zenith = config.connect_zenith(provider.clone());

rustfmt.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
reorder_imports = true
2+
use_field_init_shorthand = true
3+
use_small_heuristics = "Max"

src/config.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ impl BuilderConfig {
167167
}
168168

169169
pub async fn connect_builder_signer(&self) -> Result<LocalOrAws, ConfigError> {
170-
LocalOrAws::load(&self.builder_key, Some(self.host_chain_id))
171-
.await
172-
.map_err(Into::into)
170+
LocalOrAws::load(&self.builder_key, Some(self.host_chain_id)).await.map_err(Into::into)
173171
}
174172

175173
pub async fn connect_sequencer_signer(&self) -> Result<Option<LocalOrAws>, ConfigError> {
@@ -198,10 +196,8 @@ impl BuilderConfig {
198196
) -> Result<Vec<RootProvider<BoxTransport>>, ConfigError> {
199197
let mut providers = Vec::with_capacity(self.tx_broadcast_urls.len());
200198
for url in self.tx_broadcast_urls.iter() {
201-
let provider = ProviderBuilder::new()
202-
.on_builtin(url)
203-
.await
204-
.map_err(Into::<ConfigError>::into)?;
199+
let provider =
200+
ProviderBuilder::new().on_builtin(url).await.map_err(Into::<ConfigError>::into)?;
205201
providers.push(provider);
206202
}
207203
Ok(providers)

src/service.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,18 @@ pub struct AppError {
3030
impl AppError {
3131
/// Instantiate a new error with the bad request status code.
3232
pub fn bad_req<E: std::error::Error + Send + Sync + 'static>(e: E) -> Self {
33-
Self {
34-
code: StatusCode::BAD_REQUEST,
35-
eyre: e.into(),
36-
}
33+
Self { code: StatusCode::BAD_REQUEST, eyre: e.into() }
3734
}
3835

3936
/// Instantiate a new error with the bad request status code and an error
4037
/// string.
4138
pub fn bad_req_str(e: &str) -> Self {
42-
Self {
43-
code: StatusCode::BAD_REQUEST,
44-
eyre: eyre::eyre!(e.to_owned()),
45-
}
39+
Self { code: StatusCode::BAD_REQUEST, eyre: eyre::eyre!(e.to_owned()) }
4640
}
4741

4842
/// Instantiate a new error with the internal server error status code.
4943
pub fn server_err<E: std::error::Error + Send + Sync + 'static>(e: E) -> Self {
50-
Self {
51-
code: StatusCode::INTERNAL_SERVER_ERROR,
52-
eyre: e.into(),
53-
}
44+
Self { code: StatusCode::INTERNAL_SERVER_ERROR, eyre: e.into() }
5445
}
5546
}
5647

src/signer.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ impl LocalOrAws {
5050
async fn aws_signer(key_id: &str, chain_id: Option<u64>) -> Result<AwsSigner, SignerError> {
5151
let config = aws_config::load_defaults(BehaviorVersion::latest()).await;
5252
let client = aws_sdk_kms::Client::new(&config);
53-
AwsSigner::new(client, key_id.to_string(), chain_id)
54-
.await
55-
.map_err(Into::into)
53+
AwsSigner::new(client, key_id.to_string(), chain_id).await.map_err(Into::into)
5654
}
5755
}
5856

src/tasks/block.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ pub struct InProgressBlock {
2525
impl InProgressBlock {
2626
/// Create a new `InProgressBlock`
2727
pub fn new() -> Self {
28-
Self {
29-
transactions: Vec::new(),
30-
raw_encoding: OnceLock::new(),
31-
hash: OnceLock::new(),
32-
}
28+
Self { transactions: Vec::new(), raw_encoding: OnceLock::new(), hash: OnceLock::new() }
3329
}
3430

3531
/// Get the number of transactions in the block.
@@ -50,10 +46,8 @@ impl InProgressBlock {
5046

5147
/// Seal the block by encoding the transactions and calculating the contentshash.
5248
fn seal(&self) {
53-
self.raw_encoding
54-
.get_or_init(|| encode_txns::<Alloy2718Coder>(&self.transactions).into());
55-
self.hash
56-
.get_or_init(|| keccak256(self.raw_encoding.get().unwrap().as_ref()));
49+
self.raw_encoding.get_or_init(|| encode_txns::<Alloy2718Coder>(&self.transactions).into());
50+
self.hash.get_or_init(|| keccak256(self.raw_encoding.get().unwrap().as_ref()));
5751
}
5852

5953
/// Ingest a transaction into the in-progress block. Fails
@@ -131,19 +125,14 @@ impl BlockBuilder {
131125
pub fn spawn(
132126
self,
133127
outbound: mpsc::UnboundedSender<InProgressBlock>,
134-
) -> (
135-
mpsc::UnboundedSender<TxEnvelope>,
136-
mpsc::UnboundedSender<Bundle>,
137-
JoinHandle<()>,
138-
) {
128+
) -> (mpsc::UnboundedSender<TxEnvelope>, mpsc::UnboundedSender<Bundle>, JoinHandle<()>) {
139129
let mut in_progress = InProgressBlock::default();
140130

141131
let (tx_sender, mut tx_inbound) = mpsc::unbounded_channel();
142132
let (bundle_sender, mut bundle_inbound) = mpsc::unbounded_channel();
143133

144-
let mut sleep = Box::pin(tokio::time::sleep(Duration::from_secs(
145-
self.incoming_transactions_buffer,
146-
)));
134+
let mut sleep =
135+
Box::pin(tokio::time::sleep(Duration::from_secs(self.incoming_transactions_buffer)));
147136

148137
let handle = tokio::spawn(
149138
async move {

src/tasks/bundler.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ pub struct BundlePoller {
3535
impl BundlePoller {
3636
/// Creates a new BundlePoller from the provided builder config.
3737
pub async fn new(config: &BuilderConfig, authenticator: Authenticator) -> Self {
38-
Self {
39-
config: config.clone(),
40-
authenticator,
41-
seen_uuids: HashMap::new(),
42-
}
38+
Self { config: config.clone(), authenticator, seen_uuids: HashMap::new() }
4339
}
4440

4541
/// Fetches bundles from the transaction cache and returns the (oldest? random?) bundle in the cache.
@@ -81,13 +77,15 @@ impl BundlePoller {
8177
let expired_keys: Vec<String> = self
8278
.seen_uuids
8379
.iter()
84-
.filter_map(|(key, expiry)| {
85-
if expiry.elapsed().is_zero() {
86-
Some(key.clone())
87-
} else {
88-
None
89-
}
90-
})
80+
.filter_map(
81+
|(key, expiry)| {
82+
if expiry.elapsed().is_zero() {
83+
Some(key.clone())
84+
} else {
85+
None
86+
}
87+
},
88+
)
9189
.collect();
9290

9391
for key in expired_keys {

src/tasks/oauth.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ impl AuthenticatorInner {
4646
impl Authenticator {
4747
/// Creates a new Authenticator from the provided builder config.
4848
pub fn new(config: &BuilderConfig) -> Self {
49-
Self {
50-
config: config.clone(),
51-
inner: Arc::new(RwLock::new(AuthenticatorInner::new())),
52-
}
49+
Self { config: config.clone(), inner: Arc::new(RwLock::new(AuthenticatorInner::new())) }
5350
}
5451

5552
/// Requests a new authentication token and, if successful, sets it to as the token

src/tasks/submit.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,7 @@ impl SubmitTask {
116116
s: FixedBytes<32>,
117117
in_progress: &InProgressBlock,
118118
) -> eyre::Result<TransactionRequest> {
119-
let data = Zenith::submitBlockCall {
120-
header,
121-
v,
122-
r,
123-
s,
124-
_4: Default::default(),
125-
}
126-
.abi_encode();
119+
let data = Zenith::submitBlockCall { header, v, r, s, _4: Default::default() }.abi_encode();
127120
let sidecar = in_progress.encode_blob::<SimpleCoder>().build()?;
128121
Ok(TransactionRequest::default()
129122
.with_blob_sidecar(sidecar)
@@ -133,9 +126,7 @@ impl SubmitTask {
133126

134127
async fn next_host_block_height(&self) -> eyre::Result<u64> {
135128
let result = self.provider.get_block_number().await?;
136-
let next = result
137-
.checked_add(1)
138-
.ok_or_else(|| eyre!("next host block height overflow"))?;
129+
let next = result.checked_add(1).ok_or_else(|| eyre!("next host block height overflow"))?;
139130
Ok(next)
140131
}
141132

@@ -163,11 +154,8 @@ impl SubmitTask {
163154
.with_to(self.config.zenith_address)
164155
.with_gas_limit(1_000_000);
165156

166-
if let Err(TransportError::ErrorResp(e)) = self
167-
.provider
168-
.call(&tx)
169-
.block(BlockNumberOrTag::Pending.into())
170-
.await
157+
if let Err(TransportError::ErrorResp(e)) =
158+
self.provider.call(&tx).block(BlockNumberOrTag::Pending.into()).await
171159
{
172160
error!(
173161
code = e.code,
@@ -251,10 +239,7 @@ impl SubmitTask {
251239
sig = hex::encode(sig.as_bytes()),
252240
"acquired signature from local signer"
253241
);
254-
SignResponse {
255-
req: sig_request,
256-
sig,
257-
}
242+
SignResponse { req: sig_request, sig }
258243
} else {
259244
let resp: SignResponse = match self.sup_quincey(&sig_request).await {
260245
Ok(resp) => resp,

0 commit comments

Comments
 (0)