Migrate native bridge from ethers to alloy#24575
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
3943e33 to
1cb2053
Compare
1cb2053 to
e5616e6
Compare
e5616e6 to
05dd692
Compare
05dd692 to
0555986
Compare
0555986 to
1845423
Compare
1845423 to
2fe67c5
Compare
2fe67c5 to
0f0fc5a
Compare
0f0fc5a to
abd25d5
Compare
abd25d5 to
77b569e
Compare
7891162 to
3c480fd
Compare
3c480fd to
b7cb31a
Compare
b7cb31a to
80c2467
Compare
a532d55 to
43ae3c9
Compare
43ae3c9 to
52232f1
Compare
crates/sui-bridge/src/storage.rs
Outdated
| #[derive(DBMapUtils)] | ||
| pub struct BridgeOrchestratorTables { | ||
| /// pending BridgeActions that orchestrator received but not yet executed | ||
| pub(crate) pending_actions: DBMap<BridgeActionDigest, BridgeAction>, | ||
| /// module identifier to the last processed EventID | ||
| pub(crate) sui_syncer_cursors: DBMap<Identifier, EventID>, | ||
| /// contract address to the last processed block | ||
| pub(crate) eth_syncer_cursors: DBMap<ethers::types::Address, u64>, | ||
| pub(crate) eth_syncer_cursors: DBMap<alloy::primitives::Address, u64>, |
There was a problem hiding this comment.
This may cause an issue, can you double check that ethers::types::Address and alloy::primitives::Address have an identical serialized format? Since this is a key, specifically with the bincode serialization format.
There was a problem hiding this comment.
I added this test to check
#[tokio::test]
async fn test_address_serialization() {
let alloy_address =
alloy::primitives::Address::from_str("0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1")
.unwrap();
let ethers_address =
ethers::types::Address::from_str("0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1").unwrap();
let alloy_serialized = bincode::serialize(&alloy_address).unwrap();
let ethers_serialized = bincode::serialize(ðers_address).unwrap();
assert_eq!(alloy_serialized, ethers_serialized);
}
Unfortunately they do not match
assertion `left == right` failed
left: [20, 0, 0, 0, 0, 0, 0, 0, 144, 248, 191, 106, 71, 159, 50, 14, 173, 7, 68, 17, 164, 176, 231, 148, 78, 168, 201, 193]
right: [42, 0, 0, 0, 0, 0, 0, 0, 48, 120, 57, 48, 102, 56, 98, 102, 54, 97, 52, 55, 57, 102, 51, 50, 48, 101, 97, 100, 48, 55, 52, 52, 49, 49, 97, 52, 98, 48, 101, 55, 57, 52, 52, 101, 97, 56, 99, 57, 99, 49]
It looks like alloy serializes the address as 20 bytes (the raw address bytes) and ethers serializes the address as 42 bytes (the hex string representation starting with "0x").
I could potentially write a wrapper struct with custom serialization to preserve backwards compatibility. How does that sound?
There was a problem hiding this comment.
yep that is exactly what would be needed here, until we decided we want to do a db migration
Description
Migrated all use of the
ethersrust library toalloy.Linear issue.
Helpful documentation: https://alloy.rs/migrating-from-ethers/reference/
Test plan
Ran tests with
cargo testlocally as well as CI tests.We may need to do more extensive testing, will consult with Bridger and Brandon.