Skip to content

Fuel merge part 6 - Codegen fuel event type - #155

Merged
DZakh merged 12 commits into
mainfrom
dz/fuel-merge-5
Sep 2, 2024
Merged

Fuel merge part 6 - Codegen fuel event type#155
DZakh merged 12 commits into
mainfrom
dz/fuel-merge-5

Conversation

@DZakh

@DZakh DZakh commented Aug 29, 2024

Copy link
Copy Markdown
Member
  • Also, it cleans up our usage on Ethers. No need to create an Ethers.Interface on every getLogs call
  • Untangled system_config::Event type from the Evm abi event

Types in the handler work 🔥
image

Almost 😅

It still doesn't compile, because the rescript-schema is not generated. Also, there needs to be an adjustment for the TestHelpers module. But after it's done, I'll start working on making the engine work 🚀

@DZakh
DZakh requested a review from JonoPrest August 29, 2024 14:51
@@ -0,0 +1 @@

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept the file, so it's overwritten on the codegen (locally)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, does that mean we should always have empty files for things we remove? I would suggest just remove it. The cli handles cleaning stale generated files if the version changes.

Comment on lines 7 to 10
type interfaceAndAbi = {
interface: Ethers.Interface.t,
abi: Ethers.abi,
sighashes: array<string>,
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module doesn't look very useful anymore, probably we should refactor it in the future.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

Comment on lines -31 to -38
let getAbiMapping = (self: t) => {
self.contractAddressMapping.nameByAddress
->Js.Dict.entries
->Belt.Array.keepMap(((addr, name)) => {
self.contractNameInterfaceMapping->Js.Dict.get(name)->Belt.Option.map(v => (addr, v.abi))
})
->Js.Dict.fromArray
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused

Comment on lines -23 to -24
let {name, abi} = contract
let interface = Ethers.Interface.make(~abi)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the change, we don't need to create the Ethers.Interface anymore. It was done at least on every getLogs request. Probably not a bottleneck, but definitely good to avoid it.

Comment on lines -161 to -192
let getLogSelection = (self: t): result<array<LogSelection.t>, exn> => {
try {
self.contractAddressMapping.addressesByName
->Js.Dict.keys
->Belt.Array.map(contractName => {
let interfaceOpt = self->getInterfaceByName(~contractName)
switch interfaceOpt {
| None => UndefinedInterface(contractName)->raise
| Some({interface}) => {
let topic0 = []
//Add the topic hash from each event on the interface
interface->Ethers.Interface.forEachEvent((eventFragment, _i) => {
topic0->Js.Array2.push(eventFragment.topicHash)->ignore
})

let topicSelection = LogSelection.makeTopicSelection(~topic0)->Utils.unwrapResultExn

let addresses = []
//Add the addresses for each contract
self.contractAddressMapping
->ContractAddressingMap.getAddressesFromContractName(~contractName)
->Belt.Array.forEach(address => addresses->Js.Array2.push(address)->ignore)

LogSelection.make(~addresses, ~topicSelections=[topicSelection])
}
}
})
->Ok
} catch {
| exn => exn->Error
}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it'll most likely conflict with your changes. But I hope the new version will be more convenient to work with (moved to HyperSync worker)


// TODO: Remove in v3
@genType.import(("./OpaqueTypes.ts", "Address"))
@deprecated("Use Address.t instead. The type will be removed in v3")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remembered about the attribute :)

@JonoPrest

Copy link
Copy Markdown
Collaborator

Thanks @DZakh, I'll do a review in the morning.

Comment on lines +953 to +968
// TODO: Clean up fuel_abi to include only relevant events
Ok((events, fuel_abi))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's probably more complicated with a fuel abi to "treeshake" since there are lots types referencing each other.

I think the main reason I did it with evm code was so that there weren't some unknown discrepancies between defining values inline vs with a json ABI.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible, since there are a lot of things in the ABI we don't use

Comment on lines -1000 to -1015
#[derive(Debug, Clone, PartialEq)]
struct NormalizedEthAbiEvent(EthAbiEvent);

@JonoPrest JonoPrest Aug 30, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you've removed these type semantics. Just wanted to make you aware of the new type idiom in rust if you're not familiar: https://doc.rust-lang.org/rust-by-example/generics/new_types.html

It's useful in the sense that it shows when I use this type elsewhere that it's been parsed

let signatures = abi.get_event_signatures();

format!(
"let abi = Ethers.makeAbi((%raw(`{}`): Js.Json.t))\nlet eventSignatures = [{}]",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really mind too much but sometimes these multiline template strings read easier with a rust raw string. Kind of like template strings in js. https://rahul-thakoor.github.io/rust-raw-string-literals/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change in the next PR

Comment on lines +118 to +121
let topicSelection = LogSelection.makeTopicSelection(~topic0=contract.sighashes)->Utils.unwrapResultExn

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rather not unwrap here and then we don't need a try catch block below?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we'll need to convert array<result<_>> to result<array<>>, so I prefer throwing exception. The array is not big here, but still I don't want to add unnecessary performance overhead.

@JonoPrest JonoPrest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @DZakh, looks good so far! Nothing major just a couple of comments.

@DZakh
DZakh requested a review from JonoPrest September 2, 2024 07:19
@DZakh
DZakh enabled auto-merge (squash) September 2, 2024 08:13

@JonoPrest JonoPrest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, looking good.

@DZakh
DZakh merged commit 3fe26a8 into main Sep 2, 2024
@DZakh
DZakh deleted the dz/fuel-merge-5 branch September 2, 2024 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants