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

Contract binding generator: handle conflicting struct declarations #117

Open
pdyraga opened this issue Jun 16, 2023 · 0 comments
Open

Contract binding generator: handle conflicting struct declarations #117

pdyraga opened this issue Jun 16, 2023 · 0 comments

Comments

@pdyraga
Copy link
Member

pdyraga commented Jun 16, 2023

May depend on #45

See keep-network/keep-core#3630

after_abi_hook in keep-core renames structures that were incorrectly re-declared in the same Go package given this bug: ethereum/go-ethereum#24627.

The generated tbtc/gen/abi/Bridge.go, tbtc/gen/abi/WalletCoordinator.go, and tbtc/gen/abi/MaintainerProxy.go declare BitcoinTxInfo struct. To make the Go compiler happy, we rename BitcoinTxInfo to BitcoinTxInfo2 and BitcoinTxInfo3.

Those Go files are generated with @go run github.com/ethereum/go-ethereum/cmd/abigen.

But this is not enough! If we try to build the project with just this hook, we will encounter errors like:

pkg/chain/ethereum/tbtc/gen/contract/MaintainerProxy.go:730:3: cannot use arg_mainUtxo (variable of type "[github.com/keep-network/keep-core/pkg/chain/ethereum/tbtc/gen/abi](https://github.com/keep-network/keep-core/pkg/chain/ethereum/tbtc/gen/abi)".BitcoinTxUTXO) as type "[github.com/keep-network/keep-core/pkg/chain/ethereum/tbtc/gen/abi](https://github.com/keep-network/keep-core/pkg/chain/ethereum/tbtc/gen/abi)".BitcoinTxUTXO2 in argument to mp.contract.NotifyMovingFundsBelowDust

Looking at the generated code at the problematic line:

transaction, err := mp.contract.NotifyMovingFundsBelowDust(
  transactorOptions,
  arg_walletPubKeyHash,
  arg_mainUtxo,
)

mp.contract.NotifyFundsBelowDust is declared in the tbtc/gen/abi/MaintainerProxy.go and expects BitcoinTxUTXO2.

arg_mainUtxo from tbtc/gen/contract/MaintainerProxy.go has an incorrect type though: arg_mainUtxo abi.BitcoinTxUTXO,

Just like tbtc/gen/abi/MaintainerProxy.go this file is generated based on tbtc/gen/abi/MaintainerProxy.abi and in the *.abi file we don't have the rename performed by after_abi_hook.

The compilation error was solved with the after_contract_hook which is partially a result of ethereum/go-ethereum#24627 and partially how our Go contract bindings work. The fix from ethereum/go-ethereum#24924 will change the generated tbtc/gen/abi/*.go files but we'll have to adjust the @go run github.com/keep-network/keep-common/tools/generators/ethereum logic to follow the same naming rules as the *.abi file will remain unchanged.

lukasz-zimnoch added a commit to keep-network/keep-core that referenced this issue Jan 8, 2024
This PR fixes a compilation problem due to duplicated types that were
generated by the `abigen`.
The problem is due to an error in the version of `abigen` that we use
for contract code generation.
See keep-network/keep-common#117 for
explanation.
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

No branches or pull requests

1 participant