Skip to content
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

Tx notarization checker #471

Merged
merged 6 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions factory/runType/runTypeComponents.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package runType

import (
"errors"

"github.com/multiversx/mx-chain-proxy-go/process"
)

var errNilRunTypeComponents = errors.New("nil run type components")
axenteoctavian marked this conversation as resolved.
Show resolved Hide resolved

type runTypeComponents struct {
txNotarizationCheckerHandlerCreator process.TxNotarizationCheckerHandler
}
Expand Down
2 changes: 1 addition & 1 deletion process/factory/sovereignTxNotarizationChecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func NewSovereignTxNotarizationChecker() *sovereignTxNotarizationChecker {
return &sovereignTxNotarizationChecker{}
}

// IsNotarized returns if tx is notarized
// IsNotarized returns true
func (stnc *sovereignTxNotarizationChecker) IsNotarized(_ transaction.ApiTransactionResult) bool {
return true
}
Expand Down
21 changes: 14 additions & 7 deletions process/factory/txNotarizationChecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ func TestTxNotarizationChecker(t *testing.T) {
func TestTxNotarizationChecker_IsNotarized(t *testing.T) {
mariusmihaic marked this conversation as resolved.
Show resolved Hide resolved
t.Parallel()

tnc := NewTxNotarizationChecker()
tx := transaction.ApiTransactionResult{
NotarizedAtSourceInMetaNonce: 1,
NotarizedAtDestinationInMetaNonce: 1,
}
isNotarized := tnc.IsNotarized(tx)
require.True(t, isNotarized)
t.Run("tx is notarized, should work", func(t *testing.T) {
axenteoctavian marked this conversation as resolved.
Show resolved Hide resolved
tnc := NewTxNotarizationChecker()
tx := transaction.ApiTransactionResult{
NotarizedAtSourceInMetaNonce: 1,
NotarizedAtDestinationInMetaNonce: 1,
}
isNotarized := tnc.IsNotarized(tx)
require.True(t, isNotarized)
})
t.Run("tx is not notarized, should work", func(t *testing.T) {
tnc := NewTxNotarizationChecker()
isNotarized := tnc.IsNotarized(transaction.ApiTransactionResult{})
require.False(t, isNotarized)
})
}
3 changes: 2 additions & 1 deletion process/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-core-go/data/vm"
crypto "github.com/multiversx/mx-chain-crypto-go"

"github.com/multiversx/mx-chain-proxy-go/common"
"github.com/multiversx/mx-chain-proxy-go/data"
"github.com/multiversx/mx-chain-proxy-go/observer"
Expand Down Expand Up @@ -86,7 +87,7 @@ type HttpClient interface {
Do(req *http.Request) (*http.Response, error)
}

// TxNotarizationCheckerHandler defines a TxNotarizationCheckerHandler behavior
// TxNotarizationCheckerHandler defines what tx notarization checked should do
type TxNotarizationCheckerHandler interface {
IsNotarized(tx transaction.ApiTransactionResult) bool
IsInterfaceNil() bool
Expand Down
3 changes: 1 addition & 2 deletions process/transactionProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,7 @@ func checkIfCompleted(logs []*transaction.ApiLogs) bool {
}

func (tp *TransactionProcessor) checkIfMoveBalanceNotarized(tx *transaction.ApiTransactionResult) bool {
isNotarized := tp.txNotarizationChecker.IsNotarized(*tx)
if !isNotarized {
if !tp.txNotarizationChecker.IsNotarized(*tx) {
return false
}
isMoveBalance := tx.ProcessingTypeOnSource == moveBalanceDescriptor && tx.ProcessingTypeOnDestination == moveBalanceDescriptor
Expand Down
Loading