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

Make transactions compatible with Arbitrum and fix setting max gas price #2171

Merged
merged 4 commits into from
Feb 9, 2022

Conversation

leszko
Copy link
Contributor

@leszko leszko commented Jan 10, 2022

What does this pull request do? Explain your changes. (required)

Fix setting max gas price for both legacy tx and dynamic fee tx. Additionally, fix the transaction replacement for the legacy tx.

This PR uses TransactOpts to set GasFeeCap. There was already another approach merged to solve this issue by modifying TransactionManager #2111, but it caused to stop processing streams #2152, and therefore had to be reverted #2163.

Specific updates (required)

  • Add TransactOpts to the Client struct
  • Make all bonding contracts use TransactOpts from Client instead of the default one
  • Add lock to guard any changes to TransactOpts in Client
  • Update replace logic in transactionManager to cover legacy tx

How did you test each of these updates (required)

I didn't test the transaction replacement in Arbitrum Rinkeby Testnet

Does this pull request close any open issues?

fix #2084
fix #2243

Checklist:

@leszko leszko requested a review from yondonfu January 10, 2022 14:26
@leszko leszko changed the title 2084 max gas price trasaction opts Set GasFeeCap in each tx to maxGasPrice defined by the user Jan 10, 2022
Copy link
Member

@yondonfu yondonfu left a comment

Choose a reason for hiding this comment

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

I think there may be a problem with this approach since the client struct currently embeds each of the binding sessions. As a result, if the caller invokes a method from a binding session that isn't explicitly defined on client, the method will be invoked on the underlying binding session that defines it [1].

For example, consider the method LivepeerTokenSession.Transfer(). At the moment, Transfer() is not defined on client, so a call to client.Transfer() (such as the one here) is equivalent to client.LivepeerTokenSession.Transfer(). With the current changes in this PR, that call should result in a nil pointer error because the TransactOpts filed in LivepeerTokenSession is not set.

I suggest thinking about a way to handle this case.

[1] https://go.dev/doc/effective_go#embedding

@leszko
Copy link
Contributor Author

leszko commented Jan 14, 2022

@yondonfu Good point! You're right that it can be very confusing because you'd always need to remember that you can only use functions that were overridden in the client.

I checked and you can't configure abigen to generate only get functions in the session objects. Another approach could be to not store TransactOpts in client, but to update each session with TransactOpts while calling setTransactOpts(). Something like this.

func (c *client) setTransactOpts(opts bind.TransactOpts) {
	c.transOptsMu.Lock()
	c.LivepeerTokenSession.TransactOpts = opts
	c.LivepeerTokenFaucetSession.TransactOpts = opts
	c.ServiceRegistrySession.TransactOpts = opts
	c.BondingManagerSession.TransactOpts = opts
	// ...
	c.transOptsMu.Unlock()
}

But I think it won't work because assignment operation is not thread-safe in Go and TransactOpts is used in other places in the auto-generated Go code.

Since I don't think you can embed structs partly in Go, then I think there is no better option than getting rid of embedding the sessions at all. It results in some boilerplate delegation functions, but at least it's pretty straightforward. I added this commit: 6cdba5e . Let me know if you see any better solution to it.

@leszko leszko requested a review from yondonfu January 14, 2022 11:52
Copy link
Member

@yondonfu yondonfu left a comment

Choose a reason for hiding this comment

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

LGTM after resolving conflicts!

@yondonfu
Copy link
Member

yondonfu commented Feb 1, 2022

Let me know if you see any better solution to it.

Hm don't see an immediate better solution. The extra boilerplate is not great, but can live with it for now!

@leszko leszko force-pushed the 2084-max-gas-price-trasaction-opts branch from 6cdba5e to 5af4d77 Compare February 1, 2022 16:43
@leszko
Copy link
Contributor Author

leszko commented Feb 1, 2022

I tried to test it in Arbitrum Testnet and got the following message, which I guess is a blocker for this PR.

maxFeePerGas or maxPriorityFeePerGas specified but london is not active yet

@leszko leszko force-pushed the 2084-max-gas-price-trasaction-opts branch from 7ebebca to 31ada12 Compare February 8, 2022 08:40
@leszko leszko requested a review from yondonfu February 8, 2022 10:53
@leszko leszko changed the title Set GasFeeCap in each tx to maxGasPrice defined by the user Fix setting max gas price and transaction replcement Feb 8, 2022
Copy link
Member

@yondonfu yondonfu left a comment

Choose a reason for hiding this comment

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

LGTM. Let's update the changelog entry to reflect that this PR also make updates to be compatible with Arbitrum.

@leszko leszko force-pushed the 2084-max-gas-price-trasaction-opts branch from ff273cc to 71388bb Compare February 9, 2022 08:23
@leszko leszko changed the title Fix setting max gas price and transaction replcement Make transactions compatible with Arbitrum and fix setting max gas price Feb 9, 2022
@leszko leszko merged commit 4798627 into livepeer:master Feb 9, 2022
@leszko leszko deleted the 2084-max-gas-price-trasaction-opts branch February 9, 2022 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
2 participants