Skip to content

Commit

Permalink
Remove completely the create_coa.cdc transaction as it is not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Nov 27, 2024
1 parent eb05840 commit 31ecd72
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 125 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ start-local:
--coa-address=f8d6e0586b0a20c7 \
--coa-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
--wallet-api-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
--coa-resource-create=true \
--gas-price=0 \
--log-writer=console \
--profiler-enabled=true \
Expand All @@ -71,7 +70,6 @@ start-local-bin:
--coa-address=f8d6e0586b0a20c7 \
--coa-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
--wallet-api-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
--coa-resource-create=true \
--gas-price=0 \
--log-writer=console \
--profiler-enabled=true \
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ This will be improved soon.
_In the example above we set `coa-address` value to the service account of the emulator, the same as `coa-key`.
This account will by default be funded with Flow which is a requirement. For `coinbase` we can
use whichever valid EVM address. It's not really useful when running locally besides collecting fees. We also allow for the
`coa-resource-create` to auto-create resources needed on start-up on the `coa` account in order to operate the gateway.
`gas-price` is set at 0 so we don't have to fund EOA accounts. We can set it higher but keep in mind you will then
need funded accounts for interacting with EVM._

Expand Down Expand Up @@ -132,7 +131,6 @@ Below is an example configuration for running against testnet, with an already c
--flow-network-id=flow-testnet \
--init-cadence-height=211176670 \
--ws-enabled=true \
--coa-resource-create=false \
--coinbase=FACF71692421039876a5BB4F10EF7A439D8ef61E \
--coa-address=0x62631c28c9fc5a91 \
--coa-key=2892fba444f1d5787739708874e3b01160671924610411ac787ac1379d420f49 \
Expand Down Expand Up @@ -212,7 +210,6 @@ The application can be configured using the following flags at runtime:
| `coa-address` | `""` | Flow address holding COA account for submitting transactions |
| `coa-key` | `""` | Private key for the COA address used for transactions |
| `coa-key-file` | `""` | Path to a JSON file of COA keys for key-rotation (exclusive with `coa-key` flag) |
| `coa-resource-create` | `false` | Auto-create the COA resource if it doesn't exist in the Flow COA account |
| `coa-cloud-kms-project-id` | `""` | Project ID for KMS keys (e.g. `flow-evm-gateway`) |
| `coa-cloud-kms-location-id` | `""` | Location ID for KMS key ring (e.g. 'global') |
| `coa-cloud-kms-key-ring-id` | `""` | Key ring ID for KMS keys (e.g. 'tx-signing') |
Expand Down
1 change: 0 additions & 1 deletion cmd/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ func init() {
Cmd.Flags().StringVar(&key, "coa-key", "", "Private key value for the COA address used for submitting transactions")
Cmd.Flags().StringVar(&keyAlg, "coa-key-alg", "ECDSA_P256", "Private key algorithm for the COA private key, only effective if coa-key/coa-key-file is present. Available values (ECDSA_P256 / ECDSA_secp256k1 / BLS_BLS12_381), defaults to ECDSA_P256.")
Cmd.Flags().StringVar(&keysPath, "coa-key-file", "", "File path that contains JSON array of COA keys used in key-rotation mechanism, this is exclusive with coa-key flag.")
Cmd.Flags().BoolVar(&cfg.CreateCOAResource, "coa-resource-create", false, "Auto-create the COA resource in the Flow COA account provided if one doesn't exist")
Cmd.Flags().StringVar(&logLevel, "log-level", "debug", "Define verbosity of the log output ('debug', 'info', 'warn', 'error', 'fatal', 'panic')")
Cmd.Flags().StringVar(&logWriter, "log-writer", "stderr", "Log writer used for output ('stderr', 'console')")
Cmd.Flags().Float64Var(&cfg.StreamLimit, "stream-limit", 10, "Rate-limits the events sent to the client within one second")
Expand Down
3 changes: 0 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ type Config struct {
COAKeys []crypto.PrivateKey
// COACloudKMSKeys is a slice of all the keys and their versions that will be used in Cloud KMS key-rotation mechanism.
COACloudKMSKeys []flowGoKMS.Key
// CreateCOAResource indicates if the COA resource should be auto-created on
// startup if one doesn't exist in the COA Flow address account
CreateCOAResource bool
// GasPrice is a fixed gas price that will be used when submitting transactions.
GasPrice *big.Int
// InitCadenceHeight is used for initializing the database on a local emulator or a live network.
Expand Down
5 changes: 2 additions & 3 deletions dev/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ FLOW_NETWORK_ID=flow-emulator
COINBASE=FACF71692421039876a5BB4F10EF7A439D8ef61E
COA_ADDRESS=f8d6e0586b0a20c7
COA_KEY=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21
COA_RESOURCE_CREATE=true
GAS_PRICE=0
RPC_HOST=0.0.0.0
RPC_PORT=8545

/app/flow-evm-gateway/evm-gateway --flow-network-id=$FLOW_NETWORK_ID --coinbase=$COINBASE --coa-address=$COA_ADDRESS --coa-key=$COA_KEY --coa-resource-create=$COA_RESOURCE_CREATE --gas-price=$GAS_PRICE --rpc-host=$RPC_HOST --rpc-port=$RPC_PORT
sleep 5
/app/flow-evm-gateway/evm-gateway --flow-network-id=$FLOW_NETWORK_ID --coinbase=$COINBASE --coa-address=$COA_ADDRESS --coa-key=$COA_KEY --gas-price=$GAS_PRICE --rpc-host=$RPC_HOST --rpc-port=$RPC_PORT
sleep 5
31 changes: 0 additions & 31 deletions services/requester/cadence/create_coa.cdc

This file was deleted.

24 changes: 0 additions & 24 deletions services/requester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,11 @@ var (
//go:embed cadence/run.cdc
runTxScript []byte

//go:embed cadence/create_coa.cdc
createCOAScript []byte

//go:embed cadence/get_latest_evm_height.cdc
getLatestEVMHeight []byte
)

const minFlowBalance = 2
const coaFundingBalance = minFlowBalance - 1
const blockGasLimit = 120_000_000

type Requester interface {
Expand Down Expand Up @@ -124,9 +120,6 @@ func NewEVM(
collector metrics.Collector,
) (*EVM, error) {
logger = logger.With().Str("component", "requester").Logger()
// check that the address stores already created COA resource in the "evm" storage path.
// if it doesn't check if the auto-creation boolean is true and if so create it
// otherwise fail. COA resource is required by the EVM requester to be able to submit transactions.
address := config.COAAddress
acc, err := client.GetAccount(context.Background(), address)
if err != nil {
Expand Down Expand Up @@ -182,23 +175,6 @@ func NewEVM(
collector: collector,
}

// create COA on the account
if config.CreateCOAResource {
tx, err := evm.buildTransaction(
context.Background(),
replaceAddresses(createCOAScript, config.FlowNetworkID),
cadence.UFix64(coaFundingBalance),
)
if err != nil {
logger.Warn().Err(err).Msg("COA resource auto-creation failure")
return nil, fmt.Errorf("COA resource auto-creation failure: %w", err)
}
if err := evm.client.SendTransaction(context.Background(), *tx); err != nil {
logger.Warn().Err(err).Msg("failed to send COA resource auto-creation transaction")
return nil, fmt.Errorf("failed to send COA resource auto-creation transaction: %w", err)
}
}

return evm, nil
}

Expand Down
37 changes: 18 additions & 19 deletions tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,24 @@ func servicesSetup(t *testing.T) (emulator.Emulator, func()) {

// default config
cfg := &config.Config{
DatabaseDir: t.TempDir(),
AccessNodeHost: "localhost:3569", // emulator
RPCPort: 8545,
RPCHost: "127.0.0.1",
FlowNetworkID: "flow-emulator",
EVMNetworkID: evmTypes.FlowEVMPreviewNetChainID,
Coinbase: common.HexToAddress(coinbaseAddress),
COAAddress: service.Address,
COAKey: service.PrivateKey,
CreateCOAResource: false,
GasPrice: new(big.Int).SetUint64(150),
LogLevel: zerolog.DebugLevel,
LogWriter: testLogWriter(),
StreamTimeout: time.Second * 30,
StreamLimit: 10,
RateLimit: 500,
WSEnabled: true,
MetricsPort: 8443,
FilterExpiry: time.Second * 5,
DatabaseDir: t.TempDir(),
AccessNodeHost: "localhost:3569", // emulator
RPCPort: 8545,
RPCHost: "127.0.0.1",
FlowNetworkID: "flow-emulator",
EVMNetworkID: evmTypes.FlowEVMPreviewNetChainID,
Coinbase: common.HexToAddress(coinbaseAddress),
COAAddress: service.Address,
COAKey: service.PrivateKey,
GasPrice: new(big.Int).SetUint64(150),
LogLevel: zerolog.DebugLevel,
LogWriter: testLogWriter(),
StreamTimeout: time.Second * 30,
StreamLimit: 10,
RateLimit: 500,
WSEnabled: true,
MetricsPort: 8443,
FilterExpiry: time.Second * 5,
}

bootstrapDone := make(chan struct{})
Expand Down
75 changes: 36 additions & 39 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,18 @@ func Test_ConcurrentTransactionSubmission(t *testing.T) {
require.NoError(t, err)

cfg := &config.Config{
DatabaseDir: t.TempDir(),
AccessNodeHost: grpcHost,
RPCPort: 8545,
RPCHost: "127.0.0.1",
FlowNetworkID: "flow-emulator",
EVMNetworkID: types.FlowEVMPreviewNetChainID,
Coinbase: eoaTestAccount,
COAAddress: *createdAddr,
COAKeys: keys,
CreateCOAResource: true,
GasPrice: new(big.Int).SetUint64(0),
LogLevel: zerolog.DebugLevel,
LogWriter: testLogWriter(),
DatabaseDir: t.TempDir(),
AccessNodeHost: grpcHost,
RPCPort: 8545,
RPCHost: "127.0.0.1",
FlowNetworkID: "flow-emulator",
EVMNetworkID: types.FlowEVMPreviewNetChainID,
Coinbase: eoaTestAccount,
COAAddress: *createdAddr,
COAKeys: keys,
GasPrice: new(big.Int).SetUint64(0),
LogLevel: zerolog.DebugLevel,
LogWriter: testLogWriter(),
}

// todo change this test to use ingestion and emulator directly so we can completely remove
Expand Down Expand Up @@ -166,19 +165,18 @@ func Test_EthClientTest(t *testing.T) {
require.NoError(t, err)

cfg := &config.Config{
DatabaseDir: t.TempDir(),
AccessNodeHost: grpcHost,
RPCPort: 8545,
RPCHost: "127.0.0.1",
FlowNetworkID: "flow-emulator",
EVMNetworkID: types.FlowEVMPreviewNetChainID,
Coinbase: eoaTestAccount,
COAAddress: *createdAddr,
COAKeys: keys,
CreateCOAResource: true,
GasPrice: new(big.Int).SetUint64(150),
LogLevel: zerolog.DebugLevel,
LogWriter: testLogWriter(),
DatabaseDir: t.TempDir(),
AccessNodeHost: grpcHost,
RPCPort: 8545,
RPCHost: "127.0.0.1",
FlowNetworkID: "flow-emulator",
EVMNetworkID: types.FlowEVMPreviewNetChainID,
Coinbase: eoaTestAccount,
COAAddress: *createdAddr,
COAKeys: keys,
GasPrice: new(big.Int).SetUint64(150),
LogLevel: zerolog.DebugLevel,
LogWriter: testLogWriter(),
}

ready := make(chan struct{})
Expand Down Expand Up @@ -269,19 +267,18 @@ func Test_CloudKMSConcurrentTransactionSubmission(t *testing.T) {
require.NoError(t, err)

cfg := &config.Config{
DatabaseDir: t.TempDir(),
AccessNodeHost: grpcHost,
RPCPort: 8545,
RPCHost: "127.0.0.1",
FlowNetworkID: "flow-emulator",
EVMNetworkID: types.FlowEVMPreviewNetChainID,
Coinbase: eoaTestAccount,
COAAddress: *createdAddr,
COACloudKMSKeys: kmsKeys,
CreateCOAResource: true,
GasPrice: new(big.Int).SetUint64(0),
LogLevel: zerolog.DebugLevel,
LogWriter: testLogWriter(),
DatabaseDir: t.TempDir(),
AccessNodeHost: grpcHost,
RPCPort: 8545,
RPCHost: "127.0.0.1",
FlowNetworkID: "flow-emulator",
EVMNetworkID: types.FlowEVMPreviewNetChainID,
Coinbase: eoaTestAccount,
COAAddress: *createdAddr,
COACloudKMSKeys: kmsKeys,
GasPrice: new(big.Int).SetUint64(0),
LogLevel: zerolog.DebugLevel,
LogWriter: testLogWriter(),
}

// todo change this test to use ingestion and emulator directly so we can completely remove
Expand Down

0 comments on commit 31ecd72

Please sign in to comment.