Skip to content

Commit

Permalink
Merge pull request #699 from The-K-R-O-K/illia-malachyn/5823-payer-ha…
Browse files Browse the repository at this point in the history
…s-enough-flow-to-pay-fee

Update usage of tx validator interface
  • Loading branch information
peterargue authored Jul 18, 2024
2 parents d90a07e + 30c1193 commit a4af59d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
11 changes: 8 additions & 3 deletions emulator/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ func (b *Blockchain) ReloadBlockchain() error {
}

b.pendingBlock = newPendingBlock(latestBlock, latestLedger, b.clock)
b.transactionValidator = configureTransactionValidator(b.conf, blocks)
b.transactionValidator, err = configureTransactionValidator(b.conf, blocks)
if err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -808,7 +811,7 @@ func configureBootstrapProcedure(conf config, flowAccountKey flowgo.AccountPubli
)
}

func configureTransactionValidator(conf config, blocks *blocks) *access.TransactionValidator {
func configureTransactionValidator(conf config, blocks *blocks) (*access.TransactionValidator, error) {
return access.NewTransactionValidator(
blocks,
conf.GetChainID().Chain(),
Expand All @@ -821,7 +824,9 @@ func configureTransactionValidator(conf config, blocks *blocks) *access.Transact
CheckScriptsParse: true,
MaxTransactionByteSize: flowgo.DefaultMaxTransactionByteSize,
MaxCollectionByteSize: flowgo.DefaultMaxCollectionByteSize,
CheckPayerBalance: false,
},
nil,
)
}

Expand Down Expand Up @@ -1208,7 +1213,7 @@ func (b *Blockchain) addTransaction(tx flowgo.TransactionBody) error {
return fmt.Errorf("failed to check storage for transaction %w", err)
}

err = b.transactionValidator.Validate(&tx)
err = b.transactionValidator.Validate(context.Background(), &tx)
if err != nil {
return types.ConvertAccessError(err)
}
Expand Down
9 changes: 9 additions & 0 deletions emulator/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ func (b *blocks) FinalizedHeader() (*flowgo.Header, error) {
return block.Header, nil
}

func (b *blocks) SealedHeader() (*flowgo.Header, error) {
block, err := b.blockchain.storage.LatestBlock(context.Background())
if err != nil {
return nil, err
}

return block.Header, nil
}

// We don't have to do anything complex here, as emulator does not fork the chain
func (b *blocks) ByHeightFrom(height uint64, header *flowgo.Header) (*flowgo.Header, error) {
if height > header.Height {
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/onflow/cadence v1.0.0-preview.38
github.com/onflow/crypto v0.25.1
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.0
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1
github.com/onflow/flow-go v0.36.2-0.20240717214129-9ea6faeee3e7
github.com/onflow/flow-go-sdk v1.0.0-preview.41
github.com/onflow/flow-nft/lib/go/contracts v1.2.1
Expand Down Expand Up @@ -153,7 +153,7 @@ require (
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onflow/atree v0.7.0-rc.2 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.0 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1 // indirect
github.com/onflow/flow-ft/lib/go/contracts v1.0.0 // indirect
github.com/onflow/flow-ft/lib/go/templates v1.0.0 // indirect
github.com/onflow/flow-nft/lib/go/templates v1.2.0 // indirect
Expand Down Expand Up @@ -236,3 +236,5 @@ require (
nhooyr.io/websocket v1.8.7 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/onflow/flow-go v0.36.2-0.20240717214129-9ea6faeee3e7 => github.com/The-K-R-O-K/flow-go v0.35.14-crescendo-preview.27.0.20240718153829-58850e2c4673
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,8 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMx
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-go v0.35.14-crescendo-preview.27.0.20240718153829-58850e2c4673 h1:1MSQFa16D9E2Cnqpc870iNLB080OuhAP0TDeJyJgMzo=
github.com/The-K-R-O-K/flow-go v0.35.14-crescendo-preview.27.0.20240718153829-58850e2c4673/go.mod h1:NKttW0i0DlJYxddJoyR+E4sukr8MeCiNvtSadnZrXjY=
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=
Expand Down Expand Up @@ -2050,16 +2052,14 @@ github.com/onflow/cadence v1.0.0-preview.38/go.mod h1:jOwvPSSLTr9TvaKMs7KKiBYMmp
github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
github.com/onflow/crypto v0.25.1 h1:0txy2PKPMM873JbpxQNbJmuOJtD56bfs48RQfm0ts5A=
github.com/onflow/crypto v0.25.1/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.0 h1:cq3RfBr9TnTSnsGlUHMjMGZib24Horfb1XJqMpkN5ew=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.0/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.0 h1:aMFJdB2CW+Dzm+AJ5QN6J1yWh+a0l2RxHN2/TtLaXUo=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.0/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1 h1:q9tXLIALwQ76bO4bmSrhtTkyc2cZF4/gH11ix9E3F5k=
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-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=
github.com/onflow/flow-ft/lib/go/templates v1.0.0/go.mod h1:uQ8XFqmMK2jxyBSVrmyuwdWjTEb+6zGjRYotfDJ5pAE=
github.com/onflow/flow-go v0.36.2-0.20240717214129-9ea6faeee3e7 h1:ZlqdL88tBWCGqooqaFPgspwuwCPb+e2xE5imLEEYfTA=
github.com/onflow/flow-go v0.36.2-0.20240717214129-9ea6faeee3e7/go.mod h1:6M6tijXZLxQkzsF3IVIIuRk2lzHvMg2mVnirtLaMW18=
github.com/onflow/flow-go-sdk v1.0.0-M1/go.mod h1:TDW0MNuCs4SvqYRUzkbRnRmHQL1h4X8wURsCw9P9beo=
github.com/onflow/flow-go-sdk v1.0.0-preview.41 h1:pOUAIQdlWuc90tQzYixCXkqmnoorDgsFxTu2J1wlhHA=
github.com/onflow/flow-go-sdk v1.0.0-preview.41/go.mod h1:FyJiLluqK+sNo+ky9VU6HSwVkvhv5/fKH1sIKI1yrrI=
Expand Down

0 comments on commit a4af59d

Please sign in to comment.