-
Notifications
You must be signed in to change notification settings - Fork 180
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
[Access] Add caching tx results #4598
[Access] Add caching tx results #4598
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for picking this up @nozim! added a few comments.
On("ByBlockID", block.ID()). | ||
Return(l, nil) | ||
|
||
suite.historicalAccessClient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suite.historicalAccessClient. | |
// assert this is called exactly once for the 2 API calls | |
suite.historicalAccessClient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, added .Once(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add the comment. it makes it easier for the next person to look at these tests to quickly understand what's happening
@peterargue thank you for review, fixes on the way ;) |
@nozim please ping me when all feedback has been addressed |
e2eaf25
to
fd03e0f
Compare
@kc1116 could you please rerun ci, fixed last linter error. |
@kc1116 @peterargue kindly run the ci. Fixed all the errors. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @nozim this looks great. Also thanks for cleaning up the backend inputs. the list was getting pretty long.
Added a few small comments, but I think this is ready to go.
if params.TxResultCacheSize > 0 { | ||
txResCache, err = lru2.New[flow.Identifier, *access.TransactionResult](int(params.TxResultCacheSize)) | ||
if err != nil { | ||
params.Log.Fatal().Err(err).Msg("failed to init cache for transaction results") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my 2cents is to use the value 0 to indicate that the cache is disabled.
I originally requested that it be disabled by default to start and we can enable it in the future. It's realistically only useful on nodes where users frequently lookup non-existent TXs, so only infrastructure providers will realistically get value from it.
@@ -6,6 +6,7 @@ import ( | |||
"fmt" | |||
"time" | |||
|
|||
lru2 "github.com/hashicorp/golang-lru/v2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to a separate issue. We're already using this library within the access api, and adding a new herocache type is non-trivial.
} | ||
|
||
// Tx not found. If we have historical Sporks setup, lets look through those as well | ||
if b.txResultCache != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kc1116 this cache is here to avoid unnecessary lookups on the historic nodes since they are very expensive. the linked issue has some more context
call func(id *flow.Identity) error, | ||
shouldTerminateOnError func(node *flow.Identity, err error) bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use the original types. They help document the callbacks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was added to avoid import cycle due to mock -> backend -> mock dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i add them back I'll have to amend makefile mockgen which will differ from conventional way 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. then please move the comments from the function types into the CallAvailableNode
godocs so devs can easily see the usage details. You can remove those function types if they're unused.
Params{ | ||
State: suite.state, | ||
CollectionRPC: suite.colClient, | ||
Blocks: suite.blocks, | ||
Transactions: suite.transactions, | ||
ExecutionReceipts: suite.receipts, | ||
ChainID: suite.chainID, | ||
AccessMetrics: metrics.NewNoopCollector(), | ||
MaxHeightRange: DefaultMaxHeightRange, | ||
Log: suite.log, | ||
SnapshotHistoryLimit: DefaultSnapshotHistoryLimit, | ||
Communicator: suite.communicator, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you could add a defaultParams()
method which returns this default set. That way you don't need to repeat this block of code in each test. If you need to use a specific value for some fields, you can just update the param set before creating the backend
On("ByBlockID", block.ID()). | ||
Return(l, nil) | ||
|
||
suite.historicalAccessClient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add the comment. it makes it easier for the next person to look at these tests to quickly understand what's happening
suite.Require().Equal(flow.TransactionStatusExecuted, resp.Status) | ||
suite.Require().Equal(uint(flow.TransactionStatusExecuted), resp.StatusCode) | ||
|
||
resp2, err := backend.GetTransactionResult(context.Background(), tx.ID(), block.ID(), coll.ID()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also here
resp2, err := backend.GetTransactionResult(context.Background(), tx.ID(), block.ID(), coll.ID()) | |
// the second call should return the correct response without generating a call to the historic node | |
resp2, err := backend.GetTransactionResult(context.Background(), tx.ID(), block.ID(), coll.ID()) |
func (suite *Suite) TestGetTransactionResultCacheNonExistent() { | ||
suite.withGetTransactionCachingTestSetup(func(block *flow.Block, tx *flow.Transaction) { | ||
|
||
suite.historicalAccessClient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too
There's a PR in the works to make that suite more reliable. Once that's merged and you pull the changes, it should pass. |
@peterargue I'd be more than happy to address all your last inputs in following PR if you don't mind. |
@kc1116 kindly rerun the ci. should be fixed now. |
feel free to skip the nit, but please do address my notes about adding comments to the tests and node_communicator.go |
@peterargue kindly check 69b4339 🙏 |
Re: #4585