From bd5ce4535a345d67dd594a9659852b98cb51ea6d Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Sat, 10 Apr 2021 21:11:47 +0300 Subject: [PATCH] [#475] morph/client: Ignore "already on chain" Add checking if returned error contains "already on chain" substring. Do not consider that behavior to be erroneous. Signed-off-by: Pavel Karpy --- pkg/morph/client/notary.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/morph/client/notary.go b/pkg/morph/client/notary.go index 65e3b1f45..3669cda8f 100644 --- a/pkg/morph/client/notary.go +++ b/pkg/morph/client/notary.go @@ -1,6 +1,8 @@ package client import ( + "strings" + "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/core/transaction" @@ -284,7 +286,7 @@ func (c *Client) notaryInvoke(committee bool, contract util.Uint160, method stri 0, c.notary.fallbackTime, c.acc) - if err != nil { + if err != nil && !alreadyOnChainError(err) { return err } @@ -466,3 +468,15 @@ func WithFallbackTime(t uint32) NotaryOption { c.fallbackTime = t } } + +const alreadyOnChainErrorMessage = "already on chain" + +// Neo RPC node can return `core.ErrInvalidAttribute` error with +// `conflicting transaction <> is already on chain` message. This +// error is expected and ignored. As soon as main tx persisted on +// chain everything is fine. This happens because notary contract +// requires 5 out of 7 signatures to send main tx, thus last two +// notary requests may be processed after main tx appeared on chain. +func alreadyOnChainError(err error) bool { + return strings.Contains(err.Error(), alreadyOnChainErrorMessage) +}