-
Notifications
You must be signed in to change notification settings - Fork 741
Move context lock into issueTx #2524
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
Conversation
vms/avm/service_test.go
Outdated
@@ -622,7 +622,7 @@ func TestServiceGetTxJSON_CreateAssetTx(t *testing.T) { | |||
|
|||
// contains the address in the right format | |||
require.Contains(jsonString, `"outputs":[{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"groupID":1,"locktime":0,"threshold":1},{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"groupID":2,"locktime":0,"threshold":1}]}`) | |||
require.Contains(jsonString, `"initialStates":[{"fxIndex":0,"fxID":"spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ","outputs":[{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"locktime":0,"threshold":1},{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"locktime":0,"threshold":1}]},{"fxIndex":1,"fxID":"qd2U4HDWUvMrVUeTcCHp6xH3Qpnn1XbU5MDdnBoiifFqvgXwT","outputs":[{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"groupID":1,"locktime":0,"threshold":1},{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"groupID":2,"locktime":0,"threshold":1}]},{"fxIndex":2,"fxID":"rXJsCSEYXg2TehWxCEEGj6JU2PWKTkd6cBdNLjoe2SpsKD9cy","outputs":[{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"locktime":0,"threshold":1},{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"locktime":0,"threshold":1}]}]},"credentials":[],"id":"2MDgrsBHMRsEPa4D4NA1Bo1pjkVLUK173S3dd9BgT2nCJNiDuS"}`) | |||
require.Contains(jsonString, `"initialStates":[{"fxIndex":0,"fxID":"spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ","outputs":[{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"locktime":0,"threshold":1},{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"locktime":0,"threshold":1}]},{"fxIndex":1,"fxID":"qd2U4HDWUvMrVUeTcCHp6xH3Qpnn1XbU5MDdnBoiifFqvgXwT","outputs":[{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"groupID":1,"locktime":0,"threshold":1},{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"groupID":2,"locktime":0,"threshold":1}]},{"fxIndex":2,"fxID":"rXJsCSEYXg2TehWxCEEGj6JU2PWKTkd6cBdNLjoe2SpsKD9cy","outputs":[{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"locktime":0,"threshold":1},{"addresses":["X-testing1lnk637g0edwnqc2tn8tel39652fswa3xk4r65e"],"locktime":0,"threshold":1}]}]},"credentials":null,"id":"2MDgrsBHMRsEPa4D4NA1Bo1pjkVLUK173S3dd9BgT2nCJNiDuS"}`) |
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 is needed because we no longer parse the tx in issueTx
if !vm.bootstrapped || vm.Builder == nil { | ||
return ids.ID{}, errBootstrapping | ||
} |
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 isn't needed anymore. We only allow API traffic after bootstrapping has finished, and we are guaranteed to have Linearize called during bootstrapping.
// If onDecide is specified, the function will be called when the transaction is | ||
// either accepted or rejected with the appropriate status. This function will | ||
// go out of scope when the transaction is removed from memory. |
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 comment was very wrong... probably stale from years ago
for { | ||
txID, tx, ok := w.pendingTxs.Oldest() | ||
if !ok { | ||
return | ||
} | ||
|
||
txBytes := tx.Bytes() | ||
_, err := w.vm.IssueTx(txBytes) | ||
err := w.vm.mempool.Add(tx) |
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 is a behavior change. Previously we would validate the tx against the current state... now we just issue the tx into the mempool. Because this is only for transactions issued over the wallet API (which is deprecated) I think this minor change is fine.
if err == nil { | ||
w.vm.ctx.Log.Info("issued tx to mempool over wallet API", | ||
zap.Stringer("txID", txID), | ||
) | ||
|
||
w.vm.mempool.RequestBuildBlock() |
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.
We may want to just include this inside of Add
in the mempool.
@@ -82,11 +76,16 @@ func (w *WalletService) issue(txBytes []byte) (ids.ID, error) { | |||
} | |||
|
|||
if w.pendingTxs.Len() == 0 { | |||
_, err := w.vm.IssueTx(txBytes) | |||
if err != nil { | |||
if err := w.vm.mempool.Add(tx); err != 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.
This is again a small behavior change - same rationale as above as to why I think it is fine.
@@ -31,27 +31,26 @@ type WalletService struct { | |||
} | |||
|
|||
func (w *WalletService) decided(txID ids.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.
This is called during block.Accept
- so we must support holding the context lock here.
vm.ctx.Lock.Unlock() | ||
txID, err := vm.issueTx(tx) | ||
vm.ctx.Lock.Lock() |
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.
Why can't we modify the tests calling this to just not hold the lock?
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.
I'll make a PR on top of this PR and we can decide which we prefer
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.
@@ -302,7 +306,7 @@ func (w *WalletService) SendMultiple(_ *http.Request, args *SendMultipleArgs, re | |||
return err | |||
} | |||
|
|||
txID, err := w.issue(tx.Bytes()) | |||
txID, err := w.issue(tx) |
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.
We need to ensure atomic access between update
and issue
- so we use the context lock for exclusion throughout this API.
if err == nil { | ||
w.vm.ctx.Log.Info("issued tx to mempool over wallet API", | ||
zap.Stringer("txID", txID), | ||
) | ||
|
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.
afaict, it wouldn't be easy to change this to be called after all txs in a block have onAccept
/onReject
on them
Why this should be merged
We are moving the context lock acquisition into
network.IssueTx
. This PR separates this work to make moving the lock through boundaries clearly correct.How this works
vm.issueTx
does not hold the context lock.How this was tested