-
Notifications
You must be signed in to change notification settings - Fork 147
fix: fix Kusama sync; add storageState lock in core.HandleTransactionMessage #1783
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
Changes from 7 commits
b27e3d5
a9b7a40
6a9a5dc
4aa177b
cae4919
4c897de
1eef284
802020e
db119ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,42 +32,58 @@ func (s *Service) HandleTransactionMessage(msg *network.TransactionMessage) (boo | |
| txs := msg.Extrinsics | ||
| var toPropagate []types.Extrinsic | ||
|
|
||
| rt, err := s.blockState.GetRuntime(nil) | ||
| head, err := s.blockState.BestBlockHeader() | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| hash := head.Hash() | ||
| rt, err := s.blockState.GetRuntime(&hash) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| for _, tx := range txs { | ||
| ts, err := s.storageState.TrieState(nil) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| err = func() error { | ||
| s.storageState.Lock() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we move this lock outside of the loop?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured to put it inside the loop since if it locks outside the loop instead of for each transaction, it might cause more lock contention |
||
| defer s.storageState.Unlock() | ||
|
|
||
| rt.SetContextStorage(ts) | ||
| ts, err := s.storageState.TrieState(&head.StateRoot) //nolint | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // validate each transaction | ||
| externalExt := types.Extrinsic(append([]byte{byte(types.TxnExternal)}, tx...)) | ||
| val, err := rt.ValidateTransaction(externalExt) | ||
| if err != nil { | ||
| logger.Debug("failed to validate transaction", "err", err) | ||
| continue | ||
| } | ||
| rt.SetContextStorage(ts) | ||
|
|
||
| // validate each transaction | ||
| externalExt := types.Extrinsic(append([]byte{byte(types.TxnExternal)}, tx...)) | ||
| val, err := rt.ValidateTransaction(externalExt) | ||
| if err != nil { | ||
| logger.Debug("failed to validate transaction", "err", err) | ||
| return nil | ||
| } | ||
|
|
||
| // create new valid transaction | ||
| vtx := transaction.NewValidTransaction(tx, val) | ||
|
|
||
| // push to the transaction queue of BABE session | ||
| hash := s.transactionState.AddToPool(vtx) | ||
| logger.Trace("added transaction to pool", "hash", hash) | ||
|
|
||
| // create new valid transaction | ||
| vtx := transaction.NewValidTransaction(tx, val) | ||
| // find tx(s) that should propagate | ||
| if val.Propagate { | ||
| toPropagate = append(toPropagate, tx) | ||
| } | ||
|
|
||
| // push to the transaction queue of BABE session | ||
| hash := s.transactionState.AddToPool(vtx) | ||
| logger.Trace("Added transaction to queue", "hash", hash) | ||
| return nil | ||
| }() | ||
|
|
||
| // find tx(s) that should propagate | ||
| if val.Propagate { | ||
| toPropagate = append(toPropagate, tx) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| } | ||
|
|
||
| msg.Extrinsics = toPropagate | ||
|
|
||
| return len(msg.Extrinsics) > 0, 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.
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.
updated