Skip to content

Commit c6967df

Browse files
authored
Merge pull request #7999 from onflow/mpeter/fix-evm-vm-bridge-bootstrapping
Collect EVM-related events during VM bridge bootstrapping
2 parents df9cddf + 46df27c commit c6967df

File tree

1 file changed

+36
-46
lines changed

1 file changed

+36
-46
lines changed

fvm/bootstrap.go

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ type bootstrapExecutor struct {
306306
txnState storage.TransactionPreparer
307307

308308
accountCreator environment.BootstrapAccountCreator
309+
310+
output ProcedureOutput
309311
}
310312

311313
func newBootstrapExecutor(
@@ -319,6 +321,7 @@ func newBootstrapExecutor(
319321
ctx,
320322
WithContractDeploymentRestricted(false)),
321323
txnState: txnState,
324+
output: ProcedureOutput{},
322325
}
323326
}
324327

@@ -327,7 +330,7 @@ func (b *bootstrapExecutor) Cleanup() {
327330
}
328331

329332
func (b *bootstrapExecutor) Output() ProcedureOutput {
330-
return ProcedureOutput{}
333+
return b.output
331334
}
332335

333336
func (b *bootstrapExecutor) Preprocess() error {
@@ -1069,20 +1072,20 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
10691072
WithEVMEnabled(true),
10701073
)
10711074

1072-
run := func(tx *flow.TransactionBody, failMSG string) {
1073-
txError, err := b.invokeMetaTransaction(ctx, Transaction(tx, 0))
1074-
panicOnMetaInvokeErrf(failMSG, txError, err)
1075-
}
1075+
txIndex := uint32(0)
1076+
events := flow.EventsList{}
10761077

1077-
runAndReturn := func(tx *flow.TransactionBody, failMSG string) ProcedureOutput {
1078-
txOutput, err := b.runMetaTransaction(ctx, Transaction(tx, 0))
1078+
run := func(tx *flow.TransactionBody, failMSG string) ProcedureOutput {
1079+
txOutput, err := b.runMetaTransaction(ctx, Transaction(tx, txIndex))
10791080

10801081
if err != nil {
10811082
panic(fmt.Sprintf(failMSG, err.Error()))
10821083
}
10831084
if txOutput.Err != nil {
10841085
panic(fmt.Sprintf(failMSG, txOutput.Err.Error()))
10851086
}
1087+
txIndex += 1
1088+
events = append(events, txOutput.Events...)
10861089

10871090
return txOutput
10881091
}
@@ -1092,7 +1095,7 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
10921095
if err != nil {
10931096
panic(fmt.Sprintf("failed to build COA contract transaction: %s", err))
10941097
}
1095-
run(txBody, "failed to create COA in Service Account: %s")
1098+
_ = run(txBody, "failed to create COA in Service Account: %s")
10961099

10971100
// Arbitrary high gas limit that can be used for all the
10981101
// EVM transactions to ensure none of them run out of gas
@@ -1107,7 +1110,7 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
11071110
if err != nil {
11081111
panic(fmt.Sprintf("failed to build EVM contract transaction: %s", err))
11091112
}
1110-
txOutput := runAndReturn(txBody, "failed to deploy the Factory in the Service Account COA: %s")
1113+
txOutput := run(txBody, "failed to deploy the Factory in the Service Account COA: %s")
11111114

11121115
factoryAddress, err := getContractAddressFromEVMEvent(txOutput)
11131116
if err != nil {
@@ -1122,7 +1125,7 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
11221125
if err != nil {
11231126
panic(fmt.Sprintf("failed to build Solidity Registry contract to the service account's COA transaction: %s", err))
11241127
}
1125-
txOutput = runAndReturn(txBody, "failed to deploy the Registry in the Service Account COA: %s")
1128+
txOutput = run(txBody, "failed to deploy the Registry in the Service Account COA: %s")
11261129

11271130
registryAddress, err := getContractAddressFromEVMEvent(txOutput)
11281131
if err != nil {
@@ -1137,7 +1140,7 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
11371140
if err != nil {
11381141
panic(fmt.Sprintf("failed to build Solidity ERC20 Deployer contract to the service account's COA transaction: %s", err))
11391142
}
1140-
txOutput = runAndReturn(txBody, "failed to deploy the ERC20 Deployer in the Service Account COA: %s")
1143+
txOutput = run(txBody, "failed to deploy the ERC20 Deployer in the Service Account COA: %s")
11411144

11421145
erc20DeployerAddress, err := getContractAddressFromEVMEvent(txOutput)
11431146
if err != nil {
@@ -1151,7 +1154,7 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
11511154
if err != nil {
11521155
panic(fmt.Sprintf("failed to build ERC721 deployer contract to the service account's COA transaction: %s", err))
11531156
}
1154-
txOutput = runAndReturn(txBody, "failed to deploy the ERC721 Deployer in the Service Account COA: %s")
1157+
txOutput = run(txBody, "failed to deploy the ERC721 Deployer in the Service Account COA: %s")
11551158

11561159
erc721DeployerAddress, err := getContractAddressFromEVMEvent(txOutput)
11571160
if err != nil {
@@ -1171,27 +1174,13 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
11711174
if err != nil {
11721175
panic(fmt.Sprintf("failed to build FlowEVMBridgeUtils transaction: %s", err))
11731176
}
1174-
1175-
txError, err := b.invokeMetaTransaction(
1176-
ctx,
1177-
Transaction(
1178-
txBody,
1179-
0),
1180-
)
1181-
panicOnMetaInvokeErrf("failed to deploy FlowEVMBridgeUtils contract: %s", txError, err)
1177+
_ = run(txBody, "failed to deploy FlowEVMBridgeUtils contract: %s")
11821178
} else {
11831179
txBody, err := blueprints.DeployContractTransaction(serviceAddress, contract, name).Build()
11841180
if err != nil {
11851181
panic(fmt.Sprintf("failed to build "+name+" contract transaction: %s", err))
11861182
}
1187-
1188-
txError, err := b.invokeMetaTransaction(
1189-
ctx,
1190-
Transaction(
1191-
txBody,
1192-
0),
1193-
)
1194-
panicOnMetaInvokeErrf("failed to deploy "+name+" contract: %s", txError, err)
1183+
_ = run(txBody, "failed to deploy "+name+" contract: %s")
11951184
}
11961185
}
11971186

@@ -1200,49 +1189,49 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
12001189
if err != nil {
12011190
panic(fmt.Sprintf("failed to build pause the bridge contracts transaction: %s", err))
12021191
}
1203-
run(txBody, "failed to pause the bridge contracts: %s")
1192+
_ = run(txBody, "failed to pause the bridge contracts: %s")
12041193

12051194
// Set the factory as registrar in the registry
12061195
txBody, err = blueprints.SetRegistrarTransaction(*env, bridgeEnv, serviceAddress, registryAddress)
12071196
if err != nil {
12081197
panic(fmt.Sprintf("failed to build set the factory as register transaction: %s", err))
12091198
}
1210-
run(txBody, "failed to set the factory as registrar: %s")
1199+
_ = run(txBody, "failed to set the factory as registrar: %s")
12111200

12121201
// Add the registry to the factory
12131202
txBody, err = blueprints.SetDeploymentRegistryTransaction(*env, bridgeEnv, serviceAddress, registryAddress)
12141203
if err != nil {
12151204
panic(fmt.Sprintf("failed to build add the registry to the factory transaction: %s", err))
12161205
}
1217-
run(txBody, "failed to add the registry to the factory: %s")
1206+
_ = run(txBody, "failed to add the registry to the factory: %s")
12181207

12191208
// Set the factory as delegated deployer in the ERC20 deployer
12201209
txBody, err = blueprints.SetDelegatedDeployerTransaction(*env, bridgeEnv, serviceAddress, erc20DeployerAddress)
12211210
if err != nil {
12221211
panic(fmt.Sprintf("failed to build set the erc20 deployer as delegated deployer transaction: %s", err))
12231212
}
1224-
run(txBody, "failed to set the erc20 deployer as delegated deployer: %s")
1213+
_ = run(txBody, "failed to set the erc20 deployer as delegated deployer: %s")
12251214

12261215
// Set the factory as delegated deployer in the ERC721 deployer
12271216
txBody, err = blueprints.SetDelegatedDeployerTransaction(*env, bridgeEnv, serviceAddress, erc721DeployerAddress)
12281217
if err != nil {
12291218
panic(fmt.Sprintf("failed to build set the erc721 deployer as delegated deployer transaction: %s", err))
12301219
}
1231-
run(txBody, "failed to set the erc721 deployer as delegated deployer: %s")
1220+
_ = run(txBody, "failed to set the erc721 deployer as delegated deployer: %s")
12321221

12331222
// Add the ERC20 Deployer as a deployer in the factory
12341223
txBody, err = blueprints.AddDeployerTransaction(*env, bridgeEnv, serviceAddress, "ERC20", erc20DeployerAddress)
12351224
if err != nil {
12361225
panic(fmt.Sprintf("failed to build add the erc20 deployer in the factory transaction: %s", err))
12371226
}
1238-
run(txBody, "failed to add the erc20 deployer in the factory: %s")
1227+
_ = run(txBody, "failed to add the erc20 deployer in the factory: %s")
12391228

12401229
// Add the ERC721 Deployer as a deployer in the factory
12411230
txBody, err = blueprints.AddDeployerTransaction(*env, bridgeEnv, serviceAddress, "ERC721", erc721DeployerAddress)
12421231
if err != nil {
12431232
panic(fmt.Sprintf("failed to build add the erc721 in the factory transaction: %s", err))
12441233
}
1245-
run(txBody, "failed to add the erc721 deployer in the factory: %s")
1234+
_ = run(txBody, "failed to add the erc721 deployer in the factory: %s")
12461235

12471236
// /* --- EVM Contract Integration --- */
12481237

@@ -1251,28 +1240,28 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
12511240
if err != nil {
12521241
panic(fmt.Sprintf("failed to build deploy FlowEVMBridgeAccessor transaction: %s", err))
12531242
}
1254-
run(txBody, "failed to deploy FlowEVMBridgeAccessor contract: %s")
1243+
_ = run(txBody, "failed to deploy FlowEVMBridgeAccessor contract: %s")
12551244

12561245
// Integrate the EVM contract with the BridgeAccessor
12571246
txBody, err = blueprints.IntegrateEVMWithBridgeAccessorTransaction(*env, bridgeEnv, serviceAddress)
12581247
if err != nil {
12591248
panic(fmt.Sprintf("failed to build integrate the EVM contract with the BridgeAccessor transaction: %s", err))
12601249
}
1261-
run(txBody, "failed to integrate the EVM contract with the BridgeAccessor: %s")
1250+
_ = run(txBody, "failed to integrate the EVM contract with the BridgeAccessor: %s")
12621251

12631252
// Set the bridge onboarding fees
12641253
txBody, err = blueprints.UpdateOnboardFeeTransaction(*env, bridgeEnv, serviceAddress, 1.0)
12651254
if err != nil {
12661255
panic(fmt.Sprintf("failed to build update the bridge onboarding fees transaction: %s", err))
12671256
}
1268-
run(txBody, "failed to update the bridge onboarding fees: %s")
1257+
_ = run(txBody, "failed to update the bridge onboarding fees: %s")
12691258

12701259
// Set the bridge base fee
12711260
txBody, err = blueprints.UpdateBaseFeeTransaction(*env, bridgeEnv, serviceAddress, 0.001)
12721261
if err != nil {
12731262
panic(fmt.Sprintf("failed to build update the bridge base fees transaction: %s", err))
12741263
}
1275-
run(txBody, "failed to update the bridge base fees: %s")
1264+
_ = run(txBody, "failed to update the bridge base fees: %s")
12761265

12771266
tokenChunks := bridge.GetCadenceTokenChunkedJSONArguments(false)
12781267
nftChunks := bridge.GetCadenceTokenChunkedJSONArguments(true)
@@ -1282,14 +1271,14 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
12821271
if err != nil {
12831272
panic(fmt.Sprintf("failed to build add the FT template code chunks transaction: %s", err))
12841273
}
1285-
run(txBody, "failed to add the FT template code chunks: %s")
1274+
_ = run(txBody, "failed to add the FT template code chunks: %s")
12861275

12871276
// Add the NFT Template Cadence Code Chunks
12881277
txBody, err = blueprints.UpsertContractCodeChunksTransaction(*env, bridgeEnv, serviceAddress, "bridgedNFT", nftChunks)
12891278
if err != nil {
12901279
panic(fmt.Sprintf("failed to build add the NFT template code chunks transaction: %s", err))
12911280
}
1292-
run(txBody, "failed to add the NFT template code chunks: %s")
1281+
_ = run(txBody, "failed to add the NFT template code chunks: %s")
12931282

12941283
// Retrieve the WFLOW bytecode from the JSON args
12951284
wflowBytecode, err := bridge.GetSolidityContractCode("WFLOW")
@@ -1302,7 +1291,7 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
13021291
if err != nil {
13031292
panic(fmt.Sprintf("failed to build WFLOW contract in the Service Account COA transaction: %s", err))
13041293
}
1305-
txOutput = runAndReturn(txBody, "failed to deploy the WFLOW contract in the Service Account COA: %s")
1294+
txOutput = run(txBody, "failed to deploy the WFLOW contract in the Service Account COA: %s")
13061295

13071296
wflowAddress, err := getContractAddressFromEVMEvent(txOutput)
13081297
if err != nil {
@@ -1314,7 +1303,7 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
13141303
if err != nil {
13151304
panic(fmt.Sprintf("failed to build create the WFLOW token handler transaction: %s", err))
13161305
}
1317-
run(txBody, "failed to create the WFLOW token handler: %s")
1306+
_ = run(txBody, "failed to create the WFLOW token handler: %s")
13181307

13191308
// Enable WFLOW Token Handler, supplying the Cadence FlowToken.Vault type
13201309
flowVaultType := "A." + env.FlowTokenAddress + ".FlowToken.Vault"
@@ -1323,15 +1312,16 @@ func (b *bootstrapExecutor) setupVMBridge(serviceAddress flow.Address, env *temp
13231312
if err != nil {
13241313
panic(fmt.Sprintf("failed to build enable the WFLOW token handler transaction: %s", err))
13251314
}
1326-
run(txBody, "failed to enable the WFLOW token handler: %s")
1315+
_ = run(txBody, "failed to enable the WFLOW token handler: %s")
13271316

13281317
// Unpause the bridge
13291318
txBody, err = blueprints.PauseBridgeTransaction(*env, bridgeEnv, serviceAddress, false)
13301319
if err != nil {
13311320
panic(fmt.Sprintf("failed to build un-pause the bridge contracts transaction: %s", err))
13321321
}
1333-
run(txBody,
1334-
"failed to un-pause the bridge contracts: %s")
1322+
_ = run(txBody, "failed to un-pause the bridge contracts: %s")
1323+
1324+
b.output.Events = events
13351325
}
13361326

13371327
// getContractAddressFromEVMEvent gets the deployment address from an evm deployment transaction

0 commit comments

Comments
 (0)