rpc: improve WS-enabled transaction awaiting
Fetch blocks since VUB+1, if block received and we haven't returned the result yet, then transaction wasn't accepted at all.
This commit is contained in:
parent
673a495527
commit
71069b0ed0
1 changed files with 5 additions and 8 deletions
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
@ -138,7 +137,9 @@ func (a *Actor) waitWithWSWaiter(c RPCEventWaiter, h util.Uint256, vub uint32) (
|
||||||
}
|
}
|
||||||
close(rcvr)
|
close(rcvr)
|
||||||
}()
|
}()
|
||||||
blocksID, err := c.SubscribeForNewBlocksWithChan(nil, nil, rcvr)
|
// Execution event follows the block event, thus wait until the block next to the VUB to be sure.
|
||||||
|
since := vub + 1
|
||||||
|
blocksID, err := c.SubscribeForNewBlocksWithChan(nil, &since, rcvr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wsWaitErr = fmt.Errorf("failed to subscribe for new blocks: %w", err)
|
wsWaitErr = fmt.Errorf("failed to subscribe for new blocks: %w", err)
|
||||||
return
|
return
|
||||||
|
@ -178,12 +179,8 @@ func (a *Actor) waitWithWSWaiter(c RPCEventWaiter, h util.Uint256, vub uint32) (
|
||||||
case ntf := <-rcvr:
|
case ntf := <-rcvr:
|
||||||
switch ntf.Type {
|
switch ntf.Type {
|
||||||
case neorpc.BlockEventID:
|
case neorpc.BlockEventID:
|
||||||
block := ntf.Value.(*block.Block)
|
waitErr = ErrTxNotAccepted
|
||||||
// Execution event follows the block event, thus wait until the block next to the VUB to be sure.
|
return
|
||||||
if block.Index > vub {
|
|
||||||
waitErr = ErrTxNotAccepted
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case neorpc.ExecutionEventID:
|
case neorpc.ExecutionEventID:
|
||||||
aer := ntf.Value.(*state.AppExecResult)
|
aer := ntf.Value.(*state.AppExecResult)
|
||||||
if aer.Container.Equals(h) {
|
if aer.Container.Equals(h) {
|
||||||
|
|
Loading…
Reference in a new issue