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

Added new api to support conditional transactions (EIP-4337) #700

Merged
merged 1 commit into from
Feb 6, 2023

Conversation

pratikspatil024
Copy link
Member

Added a new API to support conditional transactions.

Here is an example request:

curl localhost:8545 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id": 1, "method":"eth_sendRawTransactionConditional", "params": ["0x7004c824391ea40b1084e4cad27d3a550e1f784d274b26ec96a09aa9ca36e66e", {"knownAccounts": {"0xadd1add1add1add1add1add1add1add1add1add1": "0x313AaDcA1750CaadC7BCB26FF08175c95DCf8E38", "0xadd2add2add2add2add2add2add2add2add2add2": {"0x0000000000000000000000000000000000000000000000000000000000000aaa": "0x0000000000000000000000000000000000000000000000000000000000000bbb", "0x0000000000000000000000000000000000000000000000000000000000000ccc": "0x0000000000000000000000000000000000000000000000000000000000000ddd"}}}]}'

// Get the last block
block, err := b.blockByHash(ctx, b.pendingBlock.ParentHash())
if err != nil {
return fmt.Errorf("could not fetch parent")
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use errors as predefined values? Also, I believe it's useful to add come context to each error and use errors.New() for defining new errors and fmt.Errorf("%w %v - any placeholders", errMyError, var1, var2...) providing additional context to an error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, this can be done.
This function is the replica of the SendTransaction function defined just above it. It is not used anywhere, and I have just kept it here because it was included in the interface.

}
// Include tx in chain
blocks, _ := core.GenerateChain(b.config, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
for _, tx := range b.pendingBlock.Transactions() {
Copy link
Contributor

Choose a reason for hiding this comment

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

could we remove variable shadowing?

Copy link
Contributor

Choose a reason for hiding this comment

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

could pending block be changed during the for loop? is it thread safe to perform such loop?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this function is used only for testing purposes, so I think this is fine. What do you think?

stateDB, _ := b.blockchain.State()

b.pendingBlock = blocks[0]
b.pendingState, _ = state.New(b.pendingBlock.Root(), stateDB.Database(), nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

could we have an error here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I will add an error check here. Thanks!

@@ -569,6 +569,8 @@ func testCallContract(t *testing.T, client *rpc.Client) {
func testAtFunctions(t *testing.T, client *rpc.Client) {
ec := NewClient(client)

sendTransactionConditional(ec)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we check the error here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we should. Will add the check. Thanks!

@pratikspatil024 pratikspatil024 force-pushed the pos-1088 branch 2 times, most recently from 0bcedcd to 503f3e5 Compare January 25, 2023 11:18
@codecov
Copy link

codecov bot commented Jan 25, 2023

Codecov Report

Base: 56.55% // Head: 56.59% // Increases project coverage by +0.04% 🎉

Coverage data is based on head (1675786) compared to base (e06376c).
Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           aa-4337     #700      +/-   ##
===========================================
+ Coverage    56.55%   56.59%   +0.04%     
===========================================
  Files          610      610              
  Lines        71128    71146      +18     
===========================================
+ Hits         40226    40267      +41     
+ Misses       27448    27431      -17     
+ Partials      3454     3448       -6     
Impacted Files Coverage Δ
accounts/abi/bind/backends/simulated.go 61.97% <0.00%> (-1.90%) ⬇️
ethclient/ethclient.go 8.36% <0.00%> (-0.13%) ⬇️
mobile/ethclient.go 0.00% <0.00%> (ø)
core/state_prefetcher.go 85.18% <0.00%> (-7.41%) ⬇️
p2p/discover/table.go 82.48% <0.00%> (-1.83%) ⬇️
p2p/discover/v4_udp.go 77.10% <0.00%> (-1.16%) ⬇️
p2p/simulations/mocker.go 30.00% <0.00%> (-1.12%) ⬇️
eth/downloader/skeleton.go 76.45% <0.00%> (-0.51%) ⬇️
p2p/discover/v5_udp.go 80.42% <0.00%> (-0.27%) ⬇️
les/downloader/downloader.go 75.15% <0.00%> (-0.11%) ⬇️
... and 14 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines 1940 to 1944
if knownAccounts["knownAccounts"] == nil {
// should we allow this?
// throwing an error, for now
return common.Hash{}, errors.New("knownAccounts is empty")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should assume this to be always non-empty. Bundlers should be fully responsible for this field.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, that makes sense.

@pratikspatil024 pratikspatil024 force-pushed the pos-1088 branch 2 times, most recently from b4e84bb to ca177db Compare January 31, 2023 05:22
@pratikspatil024 pratikspatil024 marked this pull request as ready for review February 6, 2023 05:03
@pratikspatil024 pratikspatil024 merged commit 884b124 into aa-4337 Feb 6, 2023
@pratikspatil024 pratikspatil024 deleted the pos-1088 branch February 6, 2023 05:06
pratikspatil024 added a commit that referenced this pull request Sep 13, 2023
…port EIP-4337 Bundled Transactions (#945)

* added new api to support conditional transactions (EIP-4337) (#700)

* Refactored the code and updated the miner to check for the validity of options (#793)

* refactored the code and updated the miner to check for the validity of options

* added new errors -32003 and -32005

* added unit tests

* addressed comments

* Aa 4337 update generics (#799)

* poc

* minor bug fix

* use common.Hash

* updated UnmarshalJSON function (reference - tynes)

* fix

* done

* linters

* with test

* undo some unintentional changes

---------

Co-authored-by: Pratik Patil <pratikspatil024@gmail.com>

* handelling the block range and timestamp range, also made timestamp a pointer

---------

Co-authored-by: Evgeny Danilenko <6655321@bk.ru>

* Added filtering of conditional transactions in txpool (#920)

* added filtering of conditional transactions in txpool

* minor fix in ValidateKnownAccounts

* bug fix

* Supporting nil knownAccounts

* lints

* bundled transactions are not announced/broadcasted to the peers

* fixed after upstream merge

* few fixes

* sentry reject conditional transaction

* Changed the namespace of conditional transaction API from `eth` to `bor` (#985)

* added conditional transaction to bor namespace

* test comit

* test comit

* added conditional transaction

* namespapce changed to bor

* cleanup

* cleanup

* addressed comments

* reverted changes in ValidateKnownAccounts

* addressed comments and removed unwanted code

* addressed comments

* bug fix

* lint

* removed licence from core/types/transaction_conditional_test.go

---------

Co-authored-by: Evgeny Danilenko <6655321@bk.ru>
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.

3 participants