Skip to content

Commit

Permalink
Merge pull request #156 from attestantio/proposer-configuration-overr…
Browse files Browse the repository at this point in the history
…ides

Manage execution configuration inheritence.
  • Loading branch information
mcdee authored Sep 3, 2023
2 parents b14f924 + 215ce19 commit 6236a6b
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dev:
- ensure relay configuration inherits all configuration values as expected

1.7.6:
- add User-Agent header to HTTP requests
Expand Down
2 changes: 1 addition & 1 deletion docs/executionconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ It is also possible to add and remove relays for a particular proposer, for exam

In this case the validator whose public key is `0x8021…8bbe` will use relays 1 and 3, and not relay 2.

Finally, it is possible for a proposer to use their own unique relay configuration, for example:
It is possible for a proposer to use their own unique relay configuration, for example:

```json
{
Expand Down
102 changes: 83 additions & 19 deletions services/blockrelay/v2/executionconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ func (e *ExecutionConfig) ProposerConfig(_ context.Context,
*beaconblockproposer.ProposerConfig,
error,
) {
// Set base configuration without relays.
config := &beaconblockproposer.ProposerConfig{
Relays: make([]*beaconblockproposer.RelayConfig, 0),
}

if e.FeeRecipient == nil {
config.FeeRecipient = fallbackFeeRecipient
} else {
Expand All @@ -181,7 +181,7 @@ func (e *ExecutionConfig) ProposerConfig(_ context.Context,
config.Relays = append(config.Relays, configRelay)
}

// Work through the proposer-specific options to see if one matches.
// Work through the proposer-specific configurations to see if one matches.
var accountName string
if provider, isProvider := account.(e2wtypes.AccountWalletProvider); isProvider {
accountName = fmt.Sprintf("%s/%s", provider.Wallet().Name(), account.Name())
Expand All @@ -202,7 +202,7 @@ func (e *ExecutionConfig) ProposerConfig(_ context.Context,
continue
}

// Update from proposer-level info.
// Update from proposer-specific configuration.
if proposerConfig.FeeRecipient != nil {
config.FeeRecipient = *proposerConfig.FeeRecipient
for _, configRelay := range config.Relays {
Expand Down Expand Up @@ -251,22 +251,7 @@ func (e *ExecutionConfig) ProposerConfig(_ context.Context,
// Add new relays.
for address, proposerRelayConfig := range proposerConfig.Relays {
if _, alreadyUpdated := updated[address]; !alreadyUpdated {
configRelay := &beaconblockproposer.RelayConfig{
Address: address,
}
if e.Grace == nil {
configRelay.Grace = 0
} else {
configRelay.Grace = *e.Grace
}
if e.MinValue == nil {
configRelay.MinValue = decimal.Zero
} else {
configRelay.MinValue = *e.MinValue
}
setRelayConfig(configRelay, &BaseRelayConfig{}, config.FeeRecipient, fallbackGasLimit)
updateRelayConfig(configRelay, proposerRelayConfig)
relays = append(relays, configRelay)
relays = append(relays, e.generateRelayConfig(address, proposerConfig, proposerRelayConfig, fallbackFeeRecipient, fallbackGasLimit))
}
}
config.Relays = relays
Expand All @@ -278,6 +263,85 @@ func (e *ExecutionConfig) ProposerConfig(_ context.Context,
return config, nil
}

// generateRelayConfig generates a relay configuration from the various
// tiers of existing information.
func (e *ExecutionConfig) generateRelayConfig(
address string,
proposerConfig *ProposerConfig,
proposerRelayConfig *ProposerRelayConfig,
fallbackFeeRecipient bellatrix.ExecutionAddress,
fallbackGasLimit uint64,
) *beaconblockproposer.RelayConfig {
relayConfig := &beaconblockproposer.RelayConfig{
Address: address,
PublicKey: proposerRelayConfig.PublicKey,
}

switch {
case proposerRelayConfig.FeeRecipient != nil:
// Fetch from proposer relay config.
relayConfig.FeeRecipient = *proposerRelayConfig.FeeRecipient
case proposerConfig.FeeRecipient != nil:
// Fetch from proposer config.
relayConfig.FeeRecipient = *proposerConfig.FeeRecipient
case e.FeeRecipient != nil:
// Fetch from execution config.
relayConfig.FeeRecipient = *e.FeeRecipient
default:
// No value; set to default
relayConfig.FeeRecipient = fallbackFeeRecipient
}

switch {
case proposerRelayConfig.Grace != nil:
// Fetch from proposer relay config.
relayConfig.Grace = *proposerRelayConfig.Grace
case proposerConfig.Grace != nil:
// Fetch from proposer config.
relayConfig.Grace = *proposerConfig.Grace
case e.Grace != nil:
// Fetch from execution config.
relayConfig.Grace = *e.Grace
default:
// No value; set to zero.
relayConfig.Grace = 0
}

switch {
case proposerRelayConfig.GasLimit != nil:
// Fetch from proposer relay config.
relayConfig.GasLimit = *proposerRelayConfig.GasLimit
case proposerConfig.GasLimit != nil:
// Fetch from proposer config.
relayConfig.GasLimit = *proposerConfig.GasLimit
case e.GasLimit != nil:
// Fetch from execution config.
relayConfig.GasLimit = *e.GasLimit
default:
// No value; set to default.
relayConfig.GasLimit = fallbackGasLimit
}

switch {
case relayConfig.MinValue.Sign() == 1:
// Already set; nothing to do.
case proposerRelayConfig.MinValue != nil:
// Fetch from proposer relay config.
relayConfig.MinValue = *proposerRelayConfig.MinValue
case proposerConfig.MinValue != nil:
// Fetch from proposer config.
relayConfig.MinValue = *proposerConfig.MinValue
case e.MinValue != nil:
// Fetch from execution config.
relayConfig.MinValue = *e.MinValue
default:
// No value; set to zero.
relayConfig.MinValue = decimal.Zero
}

return relayConfig
}

// setRelayConfig sets the base configuration for a relay.
func setRelayConfig(config *beaconblockproposer.RelayConfig,
relayConfig *BaseRelayConfig,
Expand Down
47 changes: 45 additions & 2 deletions services/blockrelay/v2/executionconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,17 @@ func TestConfig(t *testing.T) {
feeRecipient3 := bellatrix.ExecutionAddress{0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}
feeRecipient4 := bellatrix.ExecutionAddress{0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04}

gasLimit0 := uint64(0)
gasLimit1 := uint64(1000000)
gasLimit2 := uint64(2000000)
gasLimit3 := uint64(3000000)
gasLimit4 := uint64(4000000)

grace0 := 0 * time.Second
grace1 := time.Second
grace2 := 2 * time.Second

minValue0 := decimal.Zero
minValue1 := decimal.New(1, 0)
minValue2 := decimal.New(2, 0)

Expand Down Expand Up @@ -577,8 +580,9 @@ func TestConfig(t *testing.T) {
{
Address: "https://relay3.com/",
FeeRecipient: feeRecipient3,
GasLimit: gasLimit1,
MinValue: decimal.Zero,
GasLimit: gasLimit3,
Grace: grace2,
MinValue: minValue2,
},
},
},
Expand Down Expand Up @@ -630,6 +634,45 @@ func TestConfig(t *testing.T) {
},
},
},
{
name: "ProposerValidatorRelayExplicitZeros",
executionConfig: &v2.ExecutionConfig{
Proposers: []*v2.ProposerConfig{
{
Validator: pubkey1,
FeeRecipient: &feeRecipient3,
GasLimit: &gasLimit3,
Grace: &grace2,
MinValue: &minValue2,
ResetRelays: true,
Relays: map[string]*v2.ProposerRelayConfig{
"https://relay1.com/": {
FeeRecipient: &feeRecipient4,
GasLimit: &gasLimit0,
Grace: &grace0,
MinValue: &minValue0,
},
},
},
},
},
account: account1,
pubkey: pubkey1,
fallbackFeeRecipient: feeRecipient1,
fallbackGasLimit: gasLimit1,
expected: &beaconblockproposer.ProposerConfig{
FeeRecipient: feeRecipient3,
Relays: []*beaconblockproposer.RelayConfig{
{
Address: "https://relay1.com/",
FeeRecipient: feeRecipient4,
GasLimit: gasLimit0,
Grace: grace0,
MinValue: minValue0,
},
},
},
},
{
name: "InvalidProposerConfig",
executionConfig: &v2.ExecutionConfig{
Expand Down

0 comments on commit 6236a6b

Please sign in to comment.