From a73da566716fb79a81ba0399241e5ac5444e75c1 Mon Sep 17 00:00:00 2001 From: Andrii Slisarchuk Date: Tue, 6 Aug 2024 02:57:25 +0300 Subject: [PATCH 1/9] Implemented payer balance check mode --- access/validator.go | 38 ++++++++++++++++++- .../node_builder/access_node_builder.go | 15 ++++++++ engine/access/rpc/backend/backend.go | 18 ++++++++- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/access/validator.go b/access/validator.go index 6463632fadd..7fd7229c645 100644 --- a/access/validator.go +++ b/access/validator.go @@ -75,6 +75,35 @@ func (l *NoopLimiter) IsRateLimited(address flow.Address) bool { return false } +type PayerBalanceMode int + +const ( + WarnCheck PayerBalanceMode = iota + 1 + EnforceCheck +) + +func ParsePayerBalanceMode(s string) (PayerBalanceMode, error) { + switch s { + case WarnCheck.String(): + return WarnCheck, nil + case EnforceCheck.String(): + return EnforceCheck, nil + default: + return 0, errors.New("invalid payer balance mode") + } +} + +func (m PayerBalanceMode) String() string { + switch m { + case WarnCheck: + return "warn" + case EnforceCheck: + return "enforce" + default: + return "" + } +} + type TransactionValidationOptions struct { Expiry uint ExpiryBuffer uint @@ -85,6 +114,7 @@ type TransactionValidationOptions struct { MaxTransactionByteSize uint64 MaxCollectionByteSize uint64 CheckPayerBalance bool + CheckPayerBalanceMode PayerBalanceMode } type TransactionValidator struct { @@ -192,7 +222,13 @@ func (v *TransactionValidator) Validate(ctx context.Context, tx *flow.Transactio // are 'internal' and related to script execution process. they shouldn't // prevent the transaction from proceeding. if IsInsufficientBalanceError(err) { - return err + switch v.options.CheckPayerBalanceMode { + case WarnCheck: + log.Info().Err(err).Msg("payer has insufficient balance") + case EnforceCheck: + log.Info().Err(err).Msg("payer has insufficient balance") + return err + } } // log and ignore all other errors diff --git a/cmd/access/node_builder/access_node_builder.go b/cmd/access/node_builder/access_node_builder.go index b31ea749060..369f0bf646c 100644 --- a/cmd/access/node_builder/access_node_builder.go +++ b/cmd/access/node_builder/access_node_builder.go @@ -27,6 +27,7 @@ import ( "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" + accessNode "github.com/onflow/flow-go/access" "github.com/onflow/flow-go/admin/commands" stateSyncCommands "github.com/onflow/flow-go/admin/commands/state_synchronization" storageCommands "github.com/onflow/flow-go/admin/commands/storage" @@ -172,6 +173,7 @@ type AccessNodeConfig struct { registerCacheSize uint programCacheSize uint checkPayerBalance bool + checkPayerBalanceMode string versionControlEnabled bool } @@ -275,6 +277,7 @@ func DefaultAccessNodeConfig() *AccessNodeConfig { registerCacheSize: 0, programCacheSize: 0, checkPayerBalance: false, + checkPayerBalanceMode: accessNode.WarnCheck.String(), versionControlEnabled: true, } } @@ -1401,10 +1404,16 @@ func (builder *FlowAccessNodeBuilder) extraFlags() { "program-cache-size", defaultConfig.programCacheSize, "[experimental] number of blocks to cache for cadence programs. use 0 to disable cache. default: 0. Note: this is an experimental feature and may cause nodes to become unstable under certain workloads. Use with caution.") + + // Payer Balance flags.BoolVar(&builder.checkPayerBalance, "check-payer-balance", defaultConfig.checkPayerBalance, "checks that a transaction payer has sufficient balance to pay fees before submitting it to collection nodes") + flags.StringVar(&builder.checkPayerBalanceMode, + "check-payer-balance-mode", + defaultConfig.checkPayerBalanceMode, + "flag for payer balance validation that specifies whether or not to enforce the balance check. one of [warn(default), enforce]") }).ValidateFlags(func() error { if builder.supportsObserver && (builder.PublicNetworkConfig.BindAddress == cmd.NotSet || builder.PublicNetworkConfig.BindAddress == "") { return errors.New("public-network-address must be set if supports-observer is true") @@ -1883,6 +1892,11 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) { return nil, fmt.Errorf("transaction result query mode 'compare' is not supported") } + checkPayerBalanceMode, err := accessNode.ParsePayerBalanceMode(builder.checkPayerBalanceMode) + if err != nil { + return nil, fmt.Errorf("could not parse payer balance mode: %w", err) + } + nodeBackend, err := backend.New(backend.Params{ State: node.State, CollectionRPC: builder.CollectionRPC, @@ -1908,6 +1922,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) { ScriptExecutor: builder.ScriptExecutor, ScriptExecutionMode: scriptExecMode, CheckPayerBalance: builder.checkPayerBalance, + CheckPayerBalanceMode: checkPayerBalanceMode, EventQueryMode: eventQueryMode, BlockTracker: blockTracker, SubscriptionHandler: subscription.NewSubscriptionHandler( diff --git a/engine/access/rpc/backend/backend.go b/engine/access/rpc/backend/backend.go index 3af46045697..bb504642b1f 100644 --- a/engine/access/rpc/backend/backend.go +++ b/engine/access/rpc/backend/backend.go @@ -111,6 +111,7 @@ type Params struct { ScriptExecutor execution.ScriptExecutor ScriptExecutionMode IndexQueryMode CheckPayerBalance bool + CheckPayerBalanceMode access.PayerBalanceMode EventQueryMode IndexQueryMode BlockTracker subscription.BlockTracker SubscriptionHandler *subscription.SubscriptionHandler @@ -246,7 +247,13 @@ func New(params Params) (*Backend, error) { nodeInfo: nodeInfo, } - txValidator, err := configureTransactionValidator(params.State, params.ChainID, params.ScriptExecutor, params.CheckPayerBalance) + txValidator, err := configureTransactionValidator( + params.State, + params.ChainID, + params.ScriptExecutor, + params.CheckPayerBalance, + params.CheckPayerBalanceMode, + ) if err != nil { return nil, fmt.Errorf("could not create transaction validator: %w", err) } @@ -310,7 +317,13 @@ func identifierList(ids []string) (flow.IdentifierList, error) { return idList, nil } -func configureTransactionValidator(state protocol.State, chainID flow.ChainID, executor execution.ScriptExecutor, checkPayerBalance bool) (*access.TransactionValidator, error) { +func configureTransactionValidator( + state protocol.State, + chainID flow.ChainID, + executor execution.ScriptExecutor, + checkPayerBalance bool, + checkPayerBalanceMode access.PayerBalanceMode, +) (*access.TransactionValidator, error) { return access.NewTransactionValidator( access.NewProtocolStateBlocks(state), chainID.Chain(), @@ -324,6 +337,7 @@ func configureTransactionValidator(state protocol.State, chainID flow.ChainID, e MaxTransactionByteSize: flow.DefaultMaxTransactionByteSize, MaxCollectionByteSize: flow.DefaultMaxCollectionByteSize, CheckPayerBalance: checkPayerBalance, + CheckPayerBalanceMode: checkPayerBalanceMode, }, executor, ) From 98ad173d04ab86e2416d215d307a3544f064af75 Mon Sep 17 00:00:00 2001 From: Andrii Slisarchuk Date: Tue, 6 Aug 2024 14:49:29 +0300 Subject: [PATCH 2/9] Simplify enforce check --- access/validator.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/access/validator.go b/access/validator.go index 7fd7229c645..4407fbb21b5 100644 --- a/access/validator.go +++ b/access/validator.go @@ -222,11 +222,10 @@ func (v *TransactionValidator) Validate(ctx context.Context, tx *flow.Transactio // are 'internal' and related to script execution process. they shouldn't // prevent the transaction from proceeding. if IsInsufficientBalanceError(err) { - switch v.options.CheckPayerBalanceMode { - case WarnCheck: - log.Info().Err(err).Msg("payer has insufficient balance") - case EnforceCheck: - log.Info().Err(err).Msg("payer has insufficient balance") + log.Info().Err(err).Msg("payer has insufficient balance") + //TODO: Metrics should go here from https://github.com/onflow/flow-go/pull/6239 + + if v.options.CheckPayerBalanceMode == EnforceCheck { return err } } From 23604bb6fdc671baf0c47a949bf0ff50f19f4866 Mon Sep 17 00:00:00 2001 From: Andrii Slisarchuk Date: Tue, 6 Aug 2024 15:05:12 +0300 Subject: [PATCH 3/9] Fixed tests --- access/validator_test.go | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/access/validator_test.go b/access/validator_test.go index 1554a91cfcb..c11ce27106a 100644 --- a/access/validator_test.go +++ b/access/validator_test.go @@ -55,6 +55,7 @@ func (s *TransactionValidatorSuite) SetupTest() { s.chain = flow.Testnet.Chain() s.validatorOptions = access.TransactionValidationOptions{ CheckPayerBalance: true, + CheckPayerBalanceMode: access.EnforceCheck, MaxTransactionByteSize: flow.DefaultMaxTransactionByteSize, MaxCollectionByteSize: flow.DefaultMaxCollectionByteSize, } @@ -140,25 +141,34 @@ func (s *TransactionValidatorSuite) TestTransactionValidator_InsufficientBalance scriptExecutor. On("ExecuteAtBlockHeight", mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(actualResponse, nil). - Once() + Return(actualResponse, nil).Twice() actualAccountResponse, err := unittest.AccountFixture() assert.NoError(s.T(), err) assert.NotNil(s.T(), actualAccountResponse) - validator, err := access.NewTransactionValidator(s.blocks, s.chain, s.validatorOptions, scriptExecutor) - assert.NoError(s.T(), err) - assert.NotNil(s.T(), validator) - - txBody := unittest.TransactionBodyFixture() + validateTx := func() error { + txBody := unittest.TransactionBodyFixture() + validator, err := access.NewTransactionValidator(s.blocks, s.chain, s.validatorOptions, scriptExecutor) + assert.NoError(s.T(), err) + assert.NotNil(s.T(), validator) - expectedError := access.InsufficientBalanceError{ - Payer: unittest.AddressFixture(), - RequiredBalance: requiredBalance, + return validator.Validate(context.Background(), &txBody) } - actualErr := validator.Validate(context.Background(), &txBody) - - assert.ErrorIs(s.T(), actualErr, expectedError) + s.Run("with enforce check", func() { + err := validateTx() + + expectedError := access.InsufficientBalanceError{ + Payer: unittest.AddressFixture(), + RequiredBalance: requiredBalance, + } + assert.ErrorIs(s.T(), err, expectedError) + }) + + s.Run("with warn check", func() { + s.validatorOptions.CheckPayerBalanceMode = access.WarnCheck + err := validateTx() + assert.NoError(s.T(), err) + }) } From 274480296ecd0afd45e2b2964754aa8f760d5b06 Mon Sep 17 00:00:00 2001 From: Andrii Slisarchuk Date: Mon, 12 Aug 2024 11:10:31 +0300 Subject: [PATCH 4/9] Fixed remarks --- access/validator.go | 12 ++++++++---- access/validator_test.go | 1 - cmd/access/node_builder/access_node_builder.go | 13 +++---------- engine/access/rpc/backend/backend.go | 4 ---- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/access/validator.go b/access/validator.go index 4407fbb21b5..c5743e08bef 100644 --- a/access/validator.go +++ b/access/validator.go @@ -78,12 +78,15 @@ func (l *NoopLimiter) IsRateLimited(address flow.Address) bool { type PayerBalanceMode int const ( - WarnCheck PayerBalanceMode = iota + 1 + Disabled PayerBalanceMode = iota + WarnCheck EnforceCheck ) func ParsePayerBalanceMode(s string) (PayerBalanceMode, error) { switch s { + case Disabled.String(): + return Disabled, nil case WarnCheck.String(): return WarnCheck, nil case EnforceCheck.String(): @@ -95,6 +98,8 @@ func ParsePayerBalanceMode(s string) (PayerBalanceMode, error) { func (m PayerBalanceMode) String() string { switch m { + case Disabled: + return "disabled" case WarnCheck: return "warn" case EnforceCheck: @@ -113,7 +118,6 @@ type TransactionValidationOptions struct { CheckScriptsParse bool MaxTransactionByteSize uint64 MaxCollectionByteSize uint64 - CheckPayerBalance bool CheckPayerBalanceMode PayerBalanceMode } @@ -133,7 +137,7 @@ func NewTransactionValidator( options TransactionValidationOptions, executor execution.ScriptExecutor, ) (*TransactionValidator, error) { - if options.CheckPayerBalance && executor == nil { + if options.CheckPayerBalanceMode != Disabled && executor == nil { return nil, errors.New("transaction validator cannot use checkPayerBalance with nil executor") } @@ -422,7 +426,7 @@ func (v *TransactionValidator) checkSignatureFormat(tx *flow.TransactionBody) er } func (v *TransactionValidator) checkSufficientBalanceToPayForTransaction(ctx context.Context, tx *flow.TransactionBody) error { - if !v.options.CheckPayerBalance { + if v.options.CheckPayerBalanceMode == Disabled { return nil } diff --git a/access/validator_test.go b/access/validator_test.go index c11ce27106a..ab862574071 100644 --- a/access/validator_test.go +++ b/access/validator_test.go @@ -54,7 +54,6 @@ func (s *TransactionValidatorSuite) SetupTest() { s.chain = flow.Testnet.Chain() s.validatorOptions = access.TransactionValidationOptions{ - CheckPayerBalance: true, CheckPayerBalanceMode: access.EnforceCheck, MaxTransactionByteSize: flow.DefaultMaxTransactionByteSize, MaxCollectionByteSize: flow.DefaultMaxCollectionByteSize, diff --git a/cmd/access/node_builder/access_node_builder.go b/cmd/access/node_builder/access_node_builder.go index 369f0bf646c..bc6c16938f1 100644 --- a/cmd/access/node_builder/access_node_builder.go +++ b/cmd/access/node_builder/access_node_builder.go @@ -172,7 +172,6 @@ type AccessNodeConfig struct { registerCacheType string registerCacheSize uint programCacheSize uint - checkPayerBalance bool checkPayerBalanceMode string versionControlEnabled bool } @@ -276,8 +275,7 @@ func DefaultAccessNodeConfig() *AccessNodeConfig { registerCacheType: pstorage.CacheTypeTwoQueue.String(), registerCacheSize: 0, programCacheSize: 0, - checkPayerBalance: false, - checkPayerBalanceMode: accessNode.WarnCheck.String(), + checkPayerBalanceMode: accessNode.Disabled.String(), versionControlEnabled: true, } } @@ -1406,14 +1404,10 @@ func (builder *FlowAccessNodeBuilder) extraFlags() { "[experimental] number of blocks to cache for cadence programs. use 0 to disable cache. default: 0. Note: this is an experimental feature and may cause nodes to become unstable under certain workloads. Use with caution.") // Payer Balance - flags.BoolVar(&builder.checkPayerBalance, - "check-payer-balance", - defaultConfig.checkPayerBalance, - "checks that a transaction payer has sufficient balance to pay fees before submitting it to collection nodes") flags.StringVar(&builder.checkPayerBalanceMode, "check-payer-balance-mode", defaultConfig.checkPayerBalanceMode, - "flag for payer balance validation that specifies whether or not to enforce the balance check. one of [warn(default), enforce]") + "flag for payer balance validation that specifies whether or not to enforce the balance check. one of [disabled(default), warn, enforce]") }).ValidateFlags(func() error { if builder.supportsObserver && (builder.PublicNetworkConfig.BindAddress == cmd.NotSet || builder.PublicNetworkConfig.BindAddress == "") { return errors.New("public-network-address must be set if supports-observer is true") @@ -1477,7 +1471,7 @@ func (builder *FlowAccessNodeBuilder) extraFlags() { return errors.New("transaction-error-messages-cache-size must be greater than 0") } - if builder.checkPayerBalance && !builder.executionDataIndexingEnabled { + if builder.checkPayerBalanceMode != accessNode.Disabled.String() && !builder.executionDataIndexingEnabled { return errors.New("execution-data-indexing-enabled must be set if check-payer-balance is enabled") } @@ -1921,7 +1915,6 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) { TxErrorMessagesCacheSize: builder.TxErrorMessagesCacheSize, ScriptExecutor: builder.ScriptExecutor, ScriptExecutionMode: scriptExecMode, - CheckPayerBalance: builder.checkPayerBalance, CheckPayerBalanceMode: checkPayerBalanceMode, EventQueryMode: eventQueryMode, BlockTracker: blockTracker, diff --git a/engine/access/rpc/backend/backend.go b/engine/access/rpc/backend/backend.go index bb504642b1f..9b75e617d1b 100644 --- a/engine/access/rpc/backend/backend.go +++ b/engine/access/rpc/backend/backend.go @@ -110,7 +110,6 @@ type Params struct { TxErrorMessagesCacheSize uint ScriptExecutor execution.ScriptExecutor ScriptExecutionMode IndexQueryMode - CheckPayerBalance bool CheckPayerBalanceMode access.PayerBalanceMode EventQueryMode IndexQueryMode BlockTracker subscription.BlockTracker @@ -251,7 +250,6 @@ func New(params Params) (*Backend, error) { params.State, params.ChainID, params.ScriptExecutor, - params.CheckPayerBalance, params.CheckPayerBalanceMode, ) if err != nil { @@ -321,7 +319,6 @@ func configureTransactionValidator( state protocol.State, chainID flow.ChainID, executor execution.ScriptExecutor, - checkPayerBalance bool, checkPayerBalanceMode access.PayerBalanceMode, ) (*access.TransactionValidator, error) { return access.NewTransactionValidator( @@ -336,7 +333,6 @@ func configureTransactionValidator( MaxGasLimit: flow.DefaultMaxTransactionGasLimit, MaxTransactionByteSize: flow.DefaultMaxTransactionByteSize, MaxCollectionByteSize: flow.DefaultMaxCollectionByteSize, - CheckPayerBalance: checkPayerBalance, CheckPayerBalanceMode: checkPayerBalanceMode, }, executor, From 9ca4e0bc1097b3f36c6cee782d1bfb51099e13a0 Mon Sep 17 00:00:00 2001 From: Andrii Slisarchuk Date: Tue, 3 Sep 2024 13:41:37 +0300 Subject: [PATCH 5/9] Replace flow emulator version --- integration/go.mod | 4 +++- integration/go.sum | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/integration/go.mod b/integration/go.mod index 8723aa74250..404b539f1ff 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -25,7 +25,7 @@ require ( github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1 github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1 github.com/onflow/flow-emulator v1.0.0-preview.41.0.20240829134601-0be55d6970b5 - github.com/onflow/flow-go v0.37.7-0.20240826193109-e211841b59f5 + github.com/onflow/flow-go v0.37.7-0.20240830182756-9ac9e1889c34 github.com/onflow/flow-go-sdk v1.0.0-preview.55 github.com/onflow/flow-go/insecure v0.0.0-00010101000000-000000000000 github.com/onflow/flow/protobuf/go/flow v0.4.6 @@ -359,3 +359,5 @@ require ( replace github.com/onflow/flow-go => ../ replace github.com/onflow/flow-go/insecure => ../insecure + +replace github.com/onflow/flow-emulator v1.0.0-preview.41.0.20240829134601-0be55d6970b5 => github.com/The-K-R-O-K/flow-emulator v1.0.0-preview.12.0.20240903103527-a68bcda903d1 diff --git a/integration/go.sum b/integration/go.sum index 17fec9e6715..94b45076761 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -999,6 +999,8 @@ github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqR github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= +github.com/The-K-R-O-K/flow-emulator v1.0.0-preview.12.0.20240903103527-a68bcda903d1 h1:0FHTpn7aY/H0ufDnPhgMvlWcxLtQpVmKS/uwqVVr60I= +github.com/The-K-R-O-K/flow-emulator v1.0.0-preview.12.0.20240903103527-a68bcda903d1/go.mod h1:KJMmuvT7IEZ35GmN1y4RnEi/kCd/DPG+7lvhLVz4mnc= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o= github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI= @@ -2153,8 +2155,6 @@ github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1 h1:q9tXLIALwQ76bO4 github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg= github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1 h1:FfhMBAb78p6VAWkJ+iqdKLErGQVQgxk5w6DP5ZruWX8= github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30= -github.com/onflow/flow-emulator v1.0.0-preview.41.0.20240829134601-0be55d6970b5 h1:Z5PC3Sqvl2UemY27uwUwzkLb8EXUf+m/aEimxFzOXuc= -github.com/onflow/flow-emulator v1.0.0-preview.41.0.20240829134601-0be55d6970b5/go.mod h1:gFafyGD4Qxs+XT2BRSIjQJ86ILSmgm1VYUoCr1nVxVI= github.com/onflow/flow-ft/lib/go/contracts v1.0.0 h1:mToacZ5NWqtlWwk/7RgIl/jeKB/Sy/tIXdw90yKHcV0= github.com/onflow/flow-ft/lib/go/contracts v1.0.0/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A= github.com/onflow/flow-ft/lib/go/templates v1.0.0 h1:6cMS/lUJJ17HjKBfMO/eh0GGvnpElPgBXx7h5aoWJhs= From b04b8c6a25afd7b6c7c2e2ee33033cc00ebe1d2d Mon Sep 17 00:00:00 2001 From: Andrii Slisarchuk Date: Thu, 5 Sep 2024 14:39:04 +0300 Subject: [PATCH 6/9] Added log --- access/validator.go | 1 + 1 file changed, 1 insertion(+) diff --git a/access/validator.go b/access/validator.go index d98d551d50b..685d625681b 100644 --- a/access/validator.go +++ b/access/validator.go @@ -229,6 +229,7 @@ func (v *TransactionValidator) Validate(ctx context.Context, tx *flow.Transactio v.transactionValidationMetrics.TransactionValidationFailed(metrics.InsufficientBalance) if v.options.CheckPayerBalanceMode == EnforceCheck { + log.Warn().Err(err).Str("transactionID", tx.ID().String()).Str("payerAddress", tx.Payer.String()).Msg("enforce check error") return err } } From f231705eceb9a6c8f7b975711a36186654de17e9 Mon Sep 17 00:00:00 2001 From: Andrii Slisarchuk Date: Mon, 23 Sep 2024 11:07:31 +0300 Subject: [PATCH 7/9] added godoc to PayerBalanceMode --- access/validator.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/access/validator.go b/access/validator.go index 53937892113..61a58069c88 100644 --- a/access/validator.go +++ b/access/validator.go @@ -78,11 +78,30 @@ func (l *NoopLimiter) IsRateLimited(address flow.Address) bool { return false } +// PayerBalanceMode represents the mode for checking the payer's balance +// when validating transactions. It controls whether and how the balance +// check is performed during transaction validation. +// +// There are few modes available: +// +// - `Disabled` - Balance checking is completely disabled. No checks are +// performed to verify if the payer has sufficient balance to cover the +// transaction fees. +// - `WarnCheck` - Balance is checked, and a warning is logged if the payer +// does not have enough balance. The transaction is still accepted and +// processed regardless of the check result. +// - `EnforceCheck` - Balance is checked, and the transaction is rejected if +// the payer does not have sufficient balance to cover the transaction fees. type PayerBalanceMode int const ( + // Disabled indicates that payer balance checking is turned off. Disabled PayerBalanceMode = iota + + // WarnCheck logs a warning if the payer's balance is insufficient, but does not prevent the transaction from being accepted. WarnCheck + + // EnforceCheck prevents the transaction from being accepted if the payer's balance is insufficient to cover transaction fees. EnforceCheck ) From 09efc024e052f1b5bc0b268ffc622dc0bc7cf1dc Mon Sep 17 00:00:00 2001 From: Andrii Slisarchuk Date: Fri, 27 Sep 2024 16:30:33 +0300 Subject: [PATCH 8/9] fixed flow-emulator dependency --- integration/go.mod | 4 ++-- integration/go.sum | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/integration/go.mod b/integration/go.mod index 5077ec8fac8..703680ddf88 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -24,8 +24,8 @@ require ( github.com/onflow/crypto v0.25.2 github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1 github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1 - github.com/onflow/flow-emulator v1.0.0-preview.41.0.20240829134601-0be55d6970b5 - github.com/onflow/flow-go v0.37.7-0.20240830182756-9ac9e1889c34 + github.com/onflow/flow-emulator v1.0.1-0.20240927131812-9780997d6290 + github.com/onflow/flow-go v0.38.0-preview.0 github.com/onflow/flow-go-sdk v1.0.0-preview.55 github.com/onflow/flow-go/insecure v0.0.0-00010101000000-000000000000 github.com/onflow/flow/protobuf/go/flow v0.4.7 diff --git a/integration/go.sum b/integration/go.sum index d6d300e202d..2b72743e56c 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -999,8 +999,6 @@ github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqR github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= -github.com/The-K-R-O-K/flow-emulator v1.0.0-preview.12.0.20240903103527-a68bcda903d1 h1:0FHTpn7aY/H0ufDnPhgMvlWcxLtQpVmKS/uwqVVr60I= -github.com/The-K-R-O-K/flow-emulator v1.0.0-preview.12.0.20240903103527-a68bcda903d1/go.mod h1:KJMmuvT7IEZ35GmN1y4RnEi/kCd/DPG+7lvhLVz4mnc= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o= github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI= @@ -2155,6 +2153,8 @@ github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1 h1:q9tXLIALwQ76bO4 github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg= github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1 h1:FfhMBAb78p6VAWkJ+iqdKLErGQVQgxk5w6DP5ZruWX8= github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30= +github.com/onflow/flow-emulator v1.0.1-0.20240927131812-9780997d6290 h1:ZS15n4jBz7qw9gtc0bmeNqeI+vZGgRqbsUGPK320aRs= +github.com/onflow/flow-emulator v1.0.1-0.20240927131812-9780997d6290/go.mod h1:TxZqQJa2221oFCRFGtfh99QG/yX4kVarPhuGloqEvNc= github.com/onflow/flow-ft/lib/go/contracts v1.0.0 h1:mToacZ5NWqtlWwk/7RgIl/jeKB/Sy/tIXdw90yKHcV0= github.com/onflow/flow-ft/lib/go/contracts v1.0.0/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A= github.com/onflow/flow-ft/lib/go/templates v1.0.0 h1:6cMS/lUJJ17HjKBfMO/eh0GGvnpElPgBXx7h5aoWJhs= From bc4b885cdff4ce5cd8d7a6921a01ebf65319667d Mon Sep 17 00:00:00 2001 From: Andrii Slisarchuk Date: Mon, 30 Sep 2024 12:25:49 +0300 Subject: [PATCH 9/9] updated flow-emulator dependency --- integration/go.mod | 4 +--- integration/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/integration/go.mod b/integration/go.mod index 2602c0f8670..c6c9dc724bb 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -24,7 +24,7 @@ require ( github.com/onflow/crypto v0.25.2 github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1 github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1 - github.com/onflow/flow-emulator v1.0.1-0.20240927131812-9780997d6290 + github.com/onflow/flow-emulator v1.0.1-0.20240930092334-2f46b2112195 github.com/onflow/flow-go v0.38.0-preview.0 github.com/onflow/flow-go-sdk v1.0.0 github.com/onflow/flow-go/insecure v0.0.0-00010101000000-000000000000 @@ -359,5 +359,3 @@ require ( replace github.com/onflow/flow-go => ../ replace github.com/onflow/flow-go/insecure => ../insecure - -replace github.com/onflow/flow-emulator v1.0.0-preview.41.0.20240829134601-0be55d6970b5 => github.com/The-K-R-O-K/flow-emulator v1.0.0-preview.12.0.20240903103527-a68bcda903d1 diff --git a/integration/go.sum b/integration/go.sum index 0f1e9ef03f1..db2f27d710f 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -2153,8 +2153,8 @@ github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1 h1:q9tXLIALwQ76bO4 github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg= github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1 h1:FfhMBAb78p6VAWkJ+iqdKLErGQVQgxk5w6DP5ZruWX8= github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30= -github.com/onflow/flow-emulator v1.0.1-0.20240927131812-9780997d6290 h1:ZS15n4jBz7qw9gtc0bmeNqeI+vZGgRqbsUGPK320aRs= -github.com/onflow/flow-emulator v1.0.1-0.20240927131812-9780997d6290/go.mod h1:TxZqQJa2221oFCRFGtfh99QG/yX4kVarPhuGloqEvNc= +github.com/onflow/flow-emulator v1.0.1-0.20240930092334-2f46b2112195 h1:buM9uEW5WhFiI9hMDA90lJhokItN1Cmac3ddb0GWSbY= +github.com/onflow/flow-emulator v1.0.1-0.20240930092334-2f46b2112195/go.mod h1:b9gi9kvRfUVHmyz7cTXBsnT12oHOJisvrxpqwtFRMpM= github.com/onflow/flow-ft/lib/go/contracts v1.0.0 h1:mToacZ5NWqtlWwk/7RgIl/jeKB/Sy/tIXdw90yKHcV0= github.com/onflow/flow-ft/lib/go/contracts v1.0.0/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A= github.com/onflow/flow-ft/lib/go/templates v1.0.0 h1:6cMS/lUJJ17HjKBfMO/eh0GGvnpElPgBXx7h5aoWJhs=