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

Relax required flags when index-only mode is set #715

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 24 additions & 22 deletions bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,29 +200,31 @@ func (b *Bootstrap) StartAPIServer(ctx context.Context) error {
)

accountKeys := make([]*requester.AccountKey, 0)
account, err := b.client.GetAccount(ctx, b.config.COAAddress)
if err != nil {
return fmt.Errorf(
"failed to get signer info account for address: %s, with: %w",
b.config.COAAddress,
err,
)
}
signer, err := createSigner(ctx, b.config, b.logger)
if err != nil {
return err
}
for _, key := range account.Keys {
// Skip account keys that do not use the same Publick Key as the
// configured crypto.Signer object.
if !key.PublicKey.Equals(signer.PublicKey()) {
continue
if !b.config.IndexOnly {
account, err := b.client.GetAccount(ctx, b.config.COAAddress)
if err != nil {
return fmt.Errorf(
"failed to get signer info account for address: %s, with: %w",
b.config.COAAddress,
err,
)
}
signer, err := createSigner(ctx, b.config, b.logger)
if err != nil {
return err
}
for _, key := range account.Keys {
// Skip account keys that do not use the same Publick Key as the
// configured crypto.Signer object.
if !key.PublicKey.Equals(signer.PublicKey()) {
continue
}
accountKeys = append(accountKeys, &requester.AccountKey{
AccountKey: *key,
Address: b.config.COAAddress,
Signer: signer,
})
}
accountKeys = append(accountKeys, &requester.AccountKey{
AccountKey: *key,
Address: b.config.COAAddress,
Signer: signer,
})
}

b.keystore = requester.NewKeyStore(accountKeys)
Expand Down
110 changes: 56 additions & 54 deletions cmd/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,58 +90,71 @@ var Cmd = &cobra.Command{
}

func parseConfigFromFlags() error {
if coinbase == "" {
return fmt.Errorf("coinbase EVM address required")
}
cfg.Coinbase = gethCommon.HexToAddress(coinbase)
if cfg.Coinbase == (gethCommon.Address{}) {
return fmt.Errorf("invalid coinbase address: %s", coinbase)
}
if !cfg.IndexOnly {
if coinbase == "" {
return fmt.Errorf("coinbase EVM address required")
}
cfg.Coinbase = gethCommon.HexToAddress(coinbase)
if cfg.Coinbase == (gethCommon.Address{}) {
return fmt.Errorf("invalid coinbase address: %s", coinbase)
}

if g, ok := new(big.Int).SetString(gas, 10); ok {
cfg.GasPrice = g
} else {
return fmt.Errorf("invalid gas price")
}
cfg.COAAddress = flow.HexToAddress(coa)
if cfg.COAAddress == flow.EmptyAddress {
return fmt.Errorf("COA address value is the empty address")
}

cfg.COAAddress = flow.HexToAddress(coa)
if cfg.COAAddress == flow.EmptyAddress {
return fmt.Errorf("COA address value is the empty address")
}
if key != "" {
sigAlgo := crypto.StringToSignatureAlgorithm(keyAlg)
if sigAlgo == crypto.UnknownSignatureAlgorithm {
return fmt.Errorf("invalid signature algorithm: %s", keyAlg)
}
pkey, err := crypto.DecodePrivateKeyHex(sigAlgo, key)
if err != nil {
return fmt.Errorf("invalid COA private key: %w", err)
}
cfg.COAKey = pkey
} else if cloudKMSKey != "" {
if cloudKMSProjectID == "" || cloudKMSLocationID == "" || cloudKMSKeyRingID == "" {
return fmt.Errorf(
"using coa-cloud-kms-key requires also coa-cloud-kms-project-id & coa-cloud-kms-location-id & coa-cloud-kms-key-ring-id",
)
}

if key != "" {
sigAlgo := crypto.StringToSignatureAlgorithm(keyAlg)
if sigAlgo == crypto.UnknownSignatureAlgorithm {
return fmt.Errorf("invalid signature algorithm: %s", keyAlg)
}
pkey, err := crypto.DecodePrivateKeyHex(sigAlgo, key)
if err != nil {
return fmt.Errorf("invalid COA private key: %w", err)
}
cfg.COAKey = pkey
} else if cloudKMSKey != "" {
if cloudKMSProjectID == "" || cloudKMSLocationID == "" || cloudKMSKeyRingID == "" {
// key has the form "{keyID}@{keyVersion}"
keyParts := strings.Split(cloudKMSKey, "@")
if len(keyParts) != 2 {
return fmt.Errorf("wrong format for Cloud KMS key: %s", key)
}
cfg.COACloudKMSKey = &flowGoKMS.Key{
ProjectID: cloudKMSProjectID,
LocationID: cloudKMSLocationID,
KeyRingID: cloudKMSKeyRingID,
KeyID: keyParts[0],
KeyVersion: keyParts[1],
}
} else {
return fmt.Errorf(
"using coa-cloud-kms-keys requires also coa-cloud-kms-project-id & coa-cloud-kms-location-id & coa-cloud-kms-key-ring-id",
"must either provide coa-key / coa-cloud-kms-key",
)
}

// key has the form "{keyID}@{keyVersion}"
keyParts := strings.Split(cloudKMSKey, "@")
if len(keyParts) != 2 {
return fmt.Errorf("wrong format for Cloud KMS key: %s", key)
}
cfg.COACloudKMSKey = &flowGoKMS.Key{
ProjectID: cloudKMSProjectID,
LocationID: cloudKMSLocationID,
KeyRingID: cloudKMSKeyRingID,
KeyID: keyParts[0],
KeyVersion: keyParts[1],
if walletKey != "" {
k, err := gethCrypto.HexToECDSA(walletKey)
if err != nil {
return fmt.Errorf("invalid private key for wallet API: %w", err)
}

cfg.WalletKey = k
cfg.WalletEnabled = true
log.Warn().Msg("wallet API is enabled. Ensure this is not used in production environments.")
}
}

if g, ok := new(big.Int).SetString(gas, 10); ok {
cfg.GasPrice = g
} else {
return fmt.Errorf(
"must either provide coa-key / coa-key-path / coa-cloud-kms-keys",
)
return fmt.Errorf("invalid gas price")
}

switch flowNetwork {
Expand Down Expand Up @@ -203,17 +216,6 @@ func parseConfigFromFlags() error {
cfg.ForceStartCadenceHeight = forceStartHeight
}

if walletKey != "" {
k, err := gethCrypto.HexToECDSA(walletKey)
if err != nil {
return fmt.Errorf("invalid private key for wallet API: %w", err)
}

cfg.WalletKey = k
cfg.WalletEnabled = true
log.Warn().Msg("wallet API is enabled. Ensure this is not used in production environments.")
}

if txStateValidation == config.LocalIndexValidation {
cfg.TxStateValidation = config.LocalIndexValidation
} else if txStateValidation == config.TxSealValidation {
Expand Down
33 changes: 18 additions & 15 deletions services/requester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,25 @@ func NewEVM(
keystore *KeyStore,
) (*EVM, error) {
logger = logger.With().Str("component", "requester").Logger()
address := config.COAAddress
acc, err := client.GetAccount(context.Background(), address)
if err != nil {
return nil, fmt.Errorf(
"could not fetch the configured COA account: %s make sure it exists: %w",
address.String(),
err,
)
}

if acc.Balance < minFlowBalance {
return nil, fmt.Errorf(
"COA account must be funded with at least %d Flow, but has balance of: %d",
minFlowBalance,
acc.Balance,
)
if !config.IndexOnly {
address := config.COAAddress
acc, err := client.GetAccount(context.Background(), address)
if err != nil {
return nil, fmt.Errorf(
"could not fetch the configured COA account: %s make sure it exists: %w",
address.String(),
err,
)
}

if acc.Balance < minFlowBalance {
return nil, fmt.Errorf(
"COA account must be funded with at least %d Flow, but has balance of: %d",
minFlowBalance,
acc.Balance,
)
}
}

head := &types.Header{
Expand Down
Loading