-
Notifications
You must be signed in to change notification settings - Fork 770
Enable Cubist Signer integration #3965
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
Open
geoff-vball
wants to merge
65
commits into
master
Choose a base branch
from
signers-config-wip
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
dd5176e
Add comments to signer-config setup
richardpringle ed0c5f8
Extend siging configuration to include RPC
richardpringle dd99c36
Add default behaviour to switch
richardpringle 9f61b1c
Add timeout to signer instantiation
richardpringle f106e92
Make rpc-signer client handle the connection
richardpringle de574a4
Fix linter error
richardpringle a7e895a
Close the connection on any error
richardpringle 15a53f0
Remove special character from error message
richardpringle cc11cac
Use Go casing conventions in json config
richardpringle eeb3644
Fix default signing config behaviour
richardpringle 47e37fa
Cleanup type-check in config-test
richardpringle 505c7fb
Simply variable name for url
richardpringle 0d66c3a
Only use public config api in test
richardpringle f8837e8
Add test for default config signer with multiple inits
richardpringle 97ffb21
Merge remote-tracking branch 'origin/master' into signers-config-wip
richardpringle 7327d0f
Merge remote-tracking branch 'origin/master' into signers-config-wip
richardpringle bb56fd5
Bubble up cleanup function
richardpringle 0b22c0a
Merge remote-tracking branch 'origin/master' into signers-config-wip
richardpringle d3e2677
Merge remote-tracking branch 'origin/master' into signers-config-wip
richardpringle 193ccd4
Merge remote-tracking branch 'origin/master' into signers-config-wip
richardpringle bd77f88
Simplify default signer creation code
richardpringle 5bc1bc0
Cleanup signer creation when key path is set
richardpringle 64f1a1d
Remove redundant word in error message
richardpringle b55f05d
Fix config test name
richardpringle e85e815
Small rpc-signer-client cleanup refactor
richardpringle c8b3714
Fix the min-connect-timeout for grpc signer
richardpringle c46209e
Merge branch 'master' into signers-config-wip
geoff-vball 8a4cb7c
Merge branch 'master' into signers-config-wip
geoff-vball 99c3a48
Reconfigure signer setup
geoff-vball e23e982
Merge branch 'master' into signers-config-wip
geoff-vball e408079
Refactor config
geoff-vball c34b691
Reduce diff
geoff-vball 446b34f
Merge branch 'master' into signers-config-wip
geoff-vball de822f3
Fix tests
geoff-vball 80ed485
lint
geoff-vball a6d8add
Add logging to signer creation
geoff-vball 649447d
Merge branch 'master' into signers-config-wip
geoff-vball d79916b
Fix ordering
geoff-vball 14c5525
Lint
geoff-vball fac9f79
Merge branch 'master' into signers-config-wip
geoff-vball 8fa5525
Remove json tags from fields that are not user supplied
geoff-vball 0c15985
Remove stray comment
geoff-vball 15db2ad
Merge branch 'master' into signers-config-wip
geoff-vball 58cc0c1
Update utils/crypto/bls/signer/rpcsigner/client.go
geoff-vball f92d3be
Review fixes
geoff-vball 270d59a
Merge branch 'signers-config-wip' of github.com:ava-labs/avalanche-go…
geoff-vball 60526b1
Move signer to node package
geoff-vball 9791ff8
Merge branch 'master' into signers-config-wip
geoff-vball ba4977a
Add missing files
geoff-vball 3283340
Wrap error
geoff-vball d6512c2
Lint
geoff-vball 3aaeda8
Merge branch 'master' into signers-config-wip
geoff-vball 7018c21
Review fixes
geoff-vball 945b7a1
clean diff
joshua-kim a178493
Merge branch 'master' into signers-config-wip
geoff-vball 931fb42
Defer cancel
geoff-vball bed4148
Move signer to node.go
geoff-vball d07341b
Merge branch 'master' into signers-config-wip
geoff-vball b769bb0
nits
joshua-kim dc213df
remove env var
joshua-kim 872b353
style nits
joshua-kim 8f15194
Update config/config_test.go
geoff-vball 6170ab1
Update config/config_test.go
geoff-vball f33fbe7
Update config/config_test.go
geoff-vball 1dbf5dd
dataDir
geoff-vball File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ import ( | |
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io/fs" | ||
"math" | ||
"os" | ||
"path/filepath" | ||
|
@@ -34,10 +33,9 @@ import ( | |
"github.com/ava-labs/avalanchego/subnets" | ||
"github.com/ava-labs/avalanchego/trace" | ||
"github.com/ava-labs/avalanchego/upgrade" | ||
"github.com/ava-labs/avalanchego/utils/bag" | ||
"github.com/ava-labs/avalanchego/utils/compression" | ||
"github.com/ava-labs/avalanchego/utils/constants" | ||
"github.com/ava-labs/avalanchego/utils/crypto/bls" | ||
"github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" | ||
"github.com/ava-labs/avalanchego/utils/ips" | ||
"github.com/ava-labs/avalanchego/utils/logging" | ||
"github.com/ava-labs/avalanchego/utils/perms" | ||
|
@@ -78,11 +76,11 @@ var ( | |
errCannotTrackPrimaryNetwork = errors.New("cannot track primary network") | ||
errStakingKeyContentUnset = fmt.Errorf("%s key not set but %s set", StakingTLSKeyContentKey, StakingCertContentKey) | ||
errStakingCertContentUnset = fmt.Errorf("%s key set but %s not set", StakingTLSKeyContentKey, StakingCertContentKey) | ||
errMissingStakingSigningKeyFile = errors.New("missing staking signing key file") | ||
errPluginDirNotADirectory = errors.New("plugin dir is not a directory") | ||
errCannotReadDirectory = errors.New("cannot read directory") | ||
errUnmarshalling = errors.New("unmarshalling failed") | ||
errFileDoesNotExist = errors.New("file does not exist") | ||
errInvalidSignerConfig = fmt.Errorf("only one of the following flags can be set: %s, %s, %s, %s", StakingEphemeralSignerEnabledKey, StakingSignerKeyContentKey, StakingSignerKeyPathKey, StakingRPCSignerEndpointKey) | ||
) | ||
|
||
func getConsensusConfig(v *viper.Viper) snowball.Parameters { | ||
|
@@ -639,74 +637,15 @@ func getStakingTLSCert(v *viper.Viper) (tls.Certificate, error) { | |
} | ||
} | ||
|
||
func getStakingSigner(v *viper.Viper) (bls.Signer, error) { | ||
if v.GetBool(StakingEphemeralSignerEnabledKey) { | ||
key, err := localsigner.New() | ||
if err != nil { | ||
return nil, fmt.Errorf("couldn't generate ephemeral signing key: %w", err) | ||
} | ||
return key, nil | ||
} | ||
|
||
if v.IsSet(StakingSignerKeyContentKey) { | ||
signerKeyRawContent := v.GetString(StakingSignerKeyContentKey) | ||
signerKeyContent, err := base64.StdEncoding.DecodeString(signerKeyRawContent) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to decode base64 content: %w", err) | ||
} | ||
key, err := localsigner.FromBytes(signerKeyContent) | ||
if err != nil { | ||
return nil, fmt.Errorf("couldn't parse signing key: %w", err) | ||
} | ||
return key, nil | ||
} | ||
|
||
signingKeyPath := getExpandedArg(v, StakingSignerKeyPathKey) | ||
_, err := os.Stat(signingKeyPath) | ||
if !errors.Is(err, fs.ErrNotExist) { | ||
signingKeyBytes, err := os.ReadFile(signingKeyPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
key, err := localsigner.FromBytes(signingKeyBytes) | ||
if err != nil { | ||
return nil, fmt.Errorf("couldn't parse signing key: %w", err) | ||
} | ||
return key, nil | ||
} | ||
|
||
if v.IsSet(StakingSignerKeyPathKey) { | ||
return nil, errMissingStakingSigningKeyFile | ||
} | ||
|
||
key, err := localsigner.New() | ||
if err != nil { | ||
return nil, fmt.Errorf("couldn't generate new signing key: %w", err) | ||
} | ||
|
||
if err := os.MkdirAll(filepath.Dir(signingKeyPath), perms.ReadWriteExecute); err != nil { | ||
return nil, fmt.Errorf("couldn't create path for signing key at %s: %w", signingKeyPath, err) | ||
} | ||
|
||
keyBytes := key.ToBytes() | ||
if err := os.WriteFile(signingKeyPath, keyBytes, perms.ReadWrite); err != nil { | ||
return nil, fmt.Errorf("couldn't write new signing key to %s: %w", signingKeyPath, err) | ||
} | ||
if err := os.Chmod(signingKeyPath, perms.ReadOnly); err != nil { | ||
return nil, fmt.Errorf("couldn't restrict permissions on new signing key at %s: %w", signingKeyPath, err) | ||
} | ||
return key, nil | ||
} | ||
|
||
func getStakingConfig(v *viper.Viper, networkID uint32) (node.StakingConfig, error) { | ||
config := node.StakingConfig{ | ||
SybilProtectionEnabled: v.GetBool(SybilProtectionEnabledKey), | ||
SybilProtectionDisabledWeight: v.GetUint64(SybilProtectionDisabledWeightKey), | ||
PartialSyncPrimaryNetwork: v.GetBool(PartialSyncPrimaryNetworkKey), | ||
StakingKeyPath: getExpandedArg(v, StakingTLSKeyPathKey), | ||
StakingCertPath: getExpandedArg(v, StakingCertPathKey), | ||
StakingSignerPath: getExpandedArg(v, StakingSignerKeyPathKey), | ||
StakingTLSKeyPath: getExpandedArg(v, StakingTLSKeyPathKey), | ||
StakingTLSCertPath: getExpandedArg(v, StakingCertPathKey), | ||
Comment on lines
+645
to
+646
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed these to disambiguate from the bls signing items. |
||
} | ||
|
||
if !config.SybilProtectionEnabled && config.SybilProtectionDisabledWeight == 0 { | ||
return node.StakingConfig{}, errSybilProtectionDisabledStakerWeights | ||
} | ||
|
@@ -720,10 +659,12 @@ func getStakingConfig(v *viper.Viper, networkID uint32) (node.StakingConfig, err | |
if err != nil { | ||
return node.StakingConfig{}, err | ||
} | ||
config.StakingSigningKey, err = getStakingSigner(v) | ||
|
||
config.StakingSignerConfig, err = getStakingSignerConfig(v) | ||
if err != nil { | ||
return node.StakingConfig{}, err | ||
} | ||
|
||
if networkID != constants.MainnetID && networkID != constants.FujiID { | ||
config.UptimeRequirement = v.GetFloat64(UptimeRequirementKey) | ||
config.MinValidatorStake = v.GetUint64(MinValidatorStakeKey) | ||
|
@@ -760,6 +701,44 @@ func getStakingConfig(v *viper.Viper, networkID uint32) (node.StakingConfig, err | |
return config, nil | ||
} | ||
|
||
func getStakingSignerConfig(v *viper.Viper) (any, error) { | ||
// A maximum of one signer option can be set | ||
bools := bag.Of( | ||
v.GetBool(StakingEphemeralSignerEnabledKey), | ||
v.IsSet(StakingSignerKeyContentKey), | ||
v.IsSet(StakingSignerKeyPathKey), | ||
v.IsSet(StakingRPCSignerEndpointKey), | ||
) | ||
if bools.Count(true) > 1 { | ||
return node.StakingConfig{}, errInvalidSignerConfig | ||
} | ||
|
||
switch { | ||
case v.GetBool(StakingEphemeralSignerEnabledKey): | ||
return node.EphemeralSignerConfig{}, nil | ||
|
||
case v.IsSet(StakingSignerKeyContentKey): | ||
return node.ContentKeyConfig{ | ||
SignerKeyRawContent: getExpandedArg(v, StakingSignerKeyContentKey), | ||
}, nil | ||
|
||
case v.IsSet(StakingRPCSignerEndpointKey): | ||
return node.RPCSignerConfig{ | ||
StakingSignerRPC: getExpandedArg(v, StakingRPCSignerEndpointKey), | ||
}, nil | ||
|
||
case v.IsSet(StakingSignerKeyPathKey): | ||
return node.SignerPathConfig{ | ||
SignerKeyPath: getExpandedArg(v, StakingSignerKeyPathKey), | ||
}, nil | ||
|
||
default: | ||
return node.DefaultSignerConfig{ | ||
SignerKeyPath: getExpandedArg(v, StakingSignerKeyPathKey), | ||
}, nil | ||
} | ||
} | ||
|
||
func getTxFeeConfig(v *viper.Viper, networkID uint32) genesis.TxFeeConfig { | ||
if networkID != constants.MainnetID && networkID != constants.FujiID { | ||
return genesis.TxFeeConfig{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't getting closed during
node.Shutdown()
which was causing an error starting up a new node in the same test.