Skip to content

Commit

Permalink
Merge branch 'dynamic-resources' of github.com:rocket-pool/node-manag…
Browse files Browse the repository at this point in the history
…er-core into dynamic-resources
  • Loading branch information
jclapis committed Jul 22, 2024
2 parents d45aaaa + 55e038b commit 0a3f0e7
Show file tree
Hide file tree
Showing 21 changed files with 393 additions and 279 deletions.
7 changes: 4 additions & 3 deletions beacon/client/committees.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"sync"

"github.com/goccy/go-json"
"github.com/rocket-pool/node-manager-core/utils"
)

type Committee struct {
Index Uinteger `json:"index"`
Slot Uinteger `json:"slot"`
Validators []string `json:"validators"`
Index utils.Uinteger `json:"index"`
Slot utils.Uinteger `json:"slot"`
Validators []string `json:"validators"`
}

// Custom deserialization logic for Committee allows us to pool the validator
Expand Down
2 changes: 1 addition & 1 deletion beacon/client/std-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (c *StandardClient) GetDomainData(ctx context.Context, domainType []byte, e
func (c *StandardClient) ExitValidator(ctx context.Context, validatorIndex string, epoch uint64, signature beacon.ValidatorSignature) error {
return c.provider.Beacon_VoluntaryExits_Post(ctx, VoluntaryExitRequest{
Message: VoluntaryExitMessage{
Epoch: Uinteger(epoch),
Epoch: utils.Uinteger(epoch),
ValidatorIndex: validatorIndex,
},
Signature: signature[:],
Expand Down
153 changes: 49 additions & 104 deletions beacon/client/types.go
Original file line number Diff line number Diff line change
@@ -1,79 +1,76 @@
package client

import (
"strconv"

"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"
"github.com/rocket-pool/node-manager-core/utils"
)

// Request types
type VoluntaryExitMessage struct {
Epoch Uinteger `json:"epoch"`
ValidatorIndex string `json:"validator_index"`
Epoch utils.Uinteger `json:"epoch"`
ValidatorIndex string `json:"validator_index"`
}
type VoluntaryExitRequest struct {
Message VoluntaryExitMessage `json:"message"`
Signature ByteArray `json:"signature"`
Signature utils.ByteArray `json:"signature"`
}
type BLSToExecutionChangeMessage struct {
ValidatorIndex string `json:"validator_index"`
FromBLSPubkey ByteArray `json:"from_bls_pubkey"`
ToExecutionAddress ByteArray `json:"to_execution_address"`
ValidatorIndex string `json:"validator_index"`
FromBLSPubkey utils.ByteArray `json:"from_bls_pubkey"`
ToExecutionAddress utils.ByteArray `json:"to_execution_address"`
}
type BLSToExecutionChangeRequest struct {
Message BLSToExecutionChangeMessage `json:"message"`
Signature ByteArray `json:"signature"`
Signature utils.ByteArray `json:"signature"`
}

// Response types
type SyncStatusResponse struct {
Data struct {
IsSyncing bool `json:"is_syncing"`
HeadSlot Uinteger `json:"head_slot"`
SyncDistance Uinteger `json:"sync_distance"`
IsSyncing bool `json:"is_syncing"`
HeadSlot utils.Uinteger `json:"head_slot"`
SyncDistance utils.Uinteger `json:"sync_distance"`
} `json:"data"`
}
type Eth2ConfigResponse struct {
Data struct {
SecondsPerSlot Uinteger `json:"SECONDS_PER_SLOT"`
SlotsPerEpoch Uinteger `json:"SLOTS_PER_EPOCH"`
EpochsPerSyncCommitteePeriod Uinteger `json:"EPOCHS_PER_SYNC_COMMITTEE_PERIOD"`
CapellaForkVersion ByteArray `json:"CAPELLA_FORK_VERSION"`
SecondsPerSlot utils.Uinteger `json:"SECONDS_PER_SLOT"`
SlotsPerEpoch utils.Uinteger `json:"SLOTS_PER_EPOCH"`
EpochsPerSyncCommitteePeriod utils.Uinteger `json:"EPOCHS_PER_SYNC_COMMITTEE_PERIOD"`
CapellaForkVersion utils.ByteArray `json:"CAPELLA_FORK_VERSION"`
} `json:"data"`
}
type Eth2DepositContractResponse struct {
Data struct {
ChainID Uinteger `json:"chain_id"`
ChainID utils.Uinteger `json:"chain_id"`
Address common.Address `json:"address"`
} `json:"data"`
}
type GenesisResponse struct {
Data struct {
GenesisTime Uinteger `json:"genesis_time"`
GenesisForkVersion ByteArray `json:"genesis_fork_version"`
GenesisValidatorsRoot ByteArray `json:"genesis_validators_root"`
GenesisTime utils.Uinteger `json:"genesis_time"`
GenesisForkVersion utils.ByteArray `json:"genesis_fork_version"`
GenesisValidatorsRoot utils.ByteArray `json:"genesis_validators_root"`
} `json:"data"`
}
type FinalityCheckpointsResponse struct {
Data struct {
PreviousJustified struct {
Epoch Uinteger `json:"epoch"`
Epoch utils.Uinteger `json:"epoch"`
} `json:"previous_justified"`
CurrentJustified struct {
Epoch Uinteger `json:"epoch"`
Epoch utils.Uinteger `json:"epoch"`
} `json:"current_justified"`
Finalized struct {
Epoch Uinteger `json:"epoch"`
Epoch utils.Uinteger `json:"epoch"`
} `json:"finalized"`
} `json:"data"`
}
type ForkResponse struct {
Data struct {
PreviousVersion ByteArray `json:"previous_version"`
CurrentVersion ByteArray `json:"current_version"`
Epoch Uinteger `json:"epoch"`
PreviousVersion utils.ByteArray `json:"previous_version"`
CurrentVersion utils.ByteArray `json:"current_version"`
Epoch utils.Uinteger `json:"epoch"`
} `json:"data"`
}
type AttestationsResponse struct {
Expand All @@ -82,18 +79,18 @@ type AttestationsResponse struct {
type BeaconBlockResponse struct {
Data struct {
Message struct {
Slot Uinteger `json:"slot"`
ProposerIndex string `json:"proposer_index"`
Slot utils.Uinteger `json:"slot"`
ProposerIndex string `json:"proposer_index"`
Body struct {
Eth1Data struct {
DepositRoot ByteArray `json:"deposit_root"`
DepositCount Uinteger `json:"deposit_count"`
BlockHash ByteArray `json:"block_hash"`
DepositRoot utils.ByteArray `json:"deposit_root"`
DepositCount utils.Uinteger `json:"deposit_count"`
BlockHash utils.ByteArray `json:"block_hash"`
} `json:"eth1_data"`
Attestations []Attestation `json:"attestations"`
ExecutionPayload *struct {
FeeRecipient ByteArray `json:"fee_recipient"`
BlockNumber Uinteger `json:"block_number"`
FeeRecipient utils.ByteArray `json:"fee_recipient"`
BlockNumber utils.Uinteger `json:"block_number"`
} `json:"execution_payload"`
} `json:"body"`
} `json:"message"`
Expand All @@ -106,8 +103,8 @@ type BeaconBlockHeaderResponse struct {
Canonical bool `json:"canonical"`
Header struct {
Message struct {
Slot Uinteger `json:"slot"`
ProposerIndex string `json:"proposer_index"`
Slot utils.Uinteger `json:"slot"`
ProposerIndex string `json:"proposer_index"`
} `json:"message"`
} `json:"header"`
} `json:"data"`
Expand All @@ -116,27 +113,27 @@ type ValidatorsResponse struct {
Data []Validator `json:"data"`
}
type Validator struct {
Index string `json:"index"`
Balance Uinteger `json:"balance"`
Status string `json:"status"`
Index string `json:"index"`
Balance utils.Uinteger `json:"balance"`
Status string `json:"status"`
Validator struct {
Pubkey ByteArray `json:"pubkey"`
WithdrawalCredentials ByteArray `json:"withdrawal_credentials"`
EffectiveBalance Uinteger `json:"effective_balance"`
Slashed bool `json:"slashed"`
ActivationEligibilityEpoch Uinteger `json:"activation_eligibility_epoch"`
ActivationEpoch Uinteger `json:"activation_epoch"`
ExitEpoch Uinteger `json:"exit_epoch"`
WithdrawableEpoch Uinteger `json:"withdrawable_epoch"`
Pubkey utils.ByteArray `json:"pubkey"`
WithdrawalCredentials utils.ByteArray `json:"withdrawal_credentials"`
EffectiveBalance utils.Uinteger `json:"effective_balance"`
Slashed bool `json:"slashed"`
ActivationEligibilityEpoch utils.Uinteger `json:"activation_eligibility_epoch"`
ActivationEpoch utils.Uinteger `json:"activation_epoch"`
ExitEpoch utils.Uinteger `json:"exit_epoch"`
WithdrawableEpoch utils.Uinteger `json:"withdrawable_epoch"`
} `json:"validator"`
}
type SyncDutiesResponse struct {
Data []SyncDuty `json:"data"`
}
type SyncDuty struct {
Pubkey ByteArray `json:"pubkey"`
ValidatorIndex string `json:"validator_index"`
SyncCommitteeIndices []Uinteger `json:"validator_sync_committee_indices"`
Pubkey utils.ByteArray `json:"pubkey"`
ValidatorIndex string `json:"validator_index"`
SyncCommitteeIndices []utils.Uinteger `json:"validator_sync_committee_indices"`
}
type ProposerDutiesResponse struct {
Data []ProposerDuty `json:"data"`
Expand All @@ -152,59 +149,7 @@ type CommitteesResponse struct {
type Attestation struct {
AggregationBits string `json:"aggregation_bits"`
Data struct {
Slot Uinteger `json:"slot"`
Index Uinteger `json:"index"`
Slot utils.Uinteger `json:"slot"`
Index utils.Uinteger `json:"index"`
} `json:"data"`
}

// Unsigned integer type
type Uinteger uint64

func (i Uinteger) MarshalJSON() ([]byte, error) {
return json.Marshal(strconv.FormatUint(uint64(i), 10))
}
func (i *Uinteger) UnmarshalJSON(data []byte) error {

// Unmarshal string
var dataStr string
if err := json.Unmarshal(data, &dataStr); err != nil {
return err
}

// Parse integer value
value, err := strconv.ParseUint(dataStr, 10, 64)
if err != nil {
return err
}

// Set value and return
*i = Uinteger(value)
return nil

}

// Byte array type
type ByteArray []byte

func (b ByteArray) MarshalJSON() ([]byte, error) {
return json.Marshal(utils.EncodeHexWithPrefix(b))
}
func (b *ByteArray) UnmarshalJSON(data []byte) error {

// Unmarshal string
var dataStr string
if err := json.Unmarshal(data, &dataStr); err != nil {
return err
}

// Decode hex
value, err := utils.DecodeHex(dataStr)
if err != nil {
return err
}

// Set value and return
*b = value
return nil

}
6 changes: 2 additions & 4 deletions config/besu-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
// Constants
const (
// Tags
besuTagTest string = "hyperledger/besu:24.7.0"
besuTagProd string = "hyperledger/besu:24.7.0"
besuTag string = "hyperledger/besu:24.7.0"
)

// Configuration for Besu
Expand Down Expand Up @@ -101,8 +100,7 @@ func NewBesuConfig() *BesuConfig {
OverwriteOnUpgrade: true,
},
Default: map[Network]string{
Network_Mainnet: besuTagProd,
Network_Holesky: besuTagTest,
Network_All: besuTag,
},
},

Expand Down
39 changes: 39 additions & 0 deletions config/cfg-section.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,42 @@ func ApplyDefaults(cfg IConfigSection, network Network) {
ApplyDefaults(subconfig, network)
}
}

// Assign the default values of a config section for the provided network
func SetDefaultsForNetworks(cfg IConfigSection, defaults map[string]any, network Network) error {
// Handle the parameters
params := cfg.GetParameters()
for _, param := range params {
id := param.GetCommon().ID
val, exists := defaults[id]
if !exists {
continue
}
valString, isString := val.(string)
if !isString {
return fmt.Errorf("parameter [%s] is not a string but has a parameter ID name", id)
}
err := param.SetDefaultValueForNetwork(valString, network)
if err != nil {
return err
}
}

// Handle the subconfigs
subconfigs := cfg.GetSubconfigs()
for name, subconfig := range subconfigs {
subParams, exists := defaults[name]
if exists {
submap, isMap := subParams.(map[string]any)
if !isMap {
return fmt.Errorf("subsection [%s] is not a map, it is %s", name, reflect.TypeOf(subParams))
}
err := SetDefaultsForNetworks(subconfig, submap, network)
if err != nil {
return fmt.Errorf("error deserializing subsection [%s]: %w", name, err)
}
}
}

return nil
}
20 changes: 14 additions & 6 deletions config/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ package config

import "fmt"

// The network that this installation is configured to run on
const (
// The standard name of the Ethereum mainnet network, used for EL / CL flags
EthNetwork_Mainnet string = "mainnet"

// The standard name of the Ethereum holesky network, used for EL / CL flags
EthNetwork_Holesky string = "holesky"
)

// Type for network keys, used in NetworkSettings to uniquely define the network
type Network string

// Enum to describe the various network values
// Enum to describe well-known network keys for convenience, which may or may not be used by the application.
const (
// Unknown
Network_Unknown Network = ""

// All networks (used for parameter defaults)
Network_All Network = "all"

// The Holesky test network
Network_Holesky Network = "holesky"
// The standard key for an Ethereum mainnet config
Network_Mainnet Network = Network(EthNetwork_Mainnet)

// The Ethereum mainnet
Network_Mainnet Network = "mainnet"
// The standard key for the Holesky test network
Network_Holesky Network = Network(EthNetwork_Holesky)
)

// A Docker container name
Expand Down
6 changes: 2 additions & 4 deletions config/geth-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
// Constants
const (
// Tags
gethTagProd string = "ethereum/client-go:v1.14.7"
gethTagTest string = "ethereum/client-go:v1.14.7"
gethTag string = "ethereum/client-go:v1.14.7"
)

// Configuration for Geth
Expand Down Expand Up @@ -87,8 +86,7 @@ func NewGethConfig() *GethConfig {
OverwriteOnUpgrade: true,
},
Default: map[Network]string{
Network_Mainnet: gethTagProd,
Network_Holesky: gethTagTest,
Network_All: gethTag,
},
},

Expand Down
Loading

0 comments on commit 0a3f0e7

Please sign in to comment.