Feature: StakeHub Contract Interface Implementation#3045
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements the StakeHub contract interface to manage validator and node ID registrations. The key changes include:
- Adding node ID registration logic during mining startup in eth/backend.go.
- Implementing StakeHub contract functions (GetValidators, ListNodeIDsFor, GetNodeIDs, AddNodeIDs) in consensus/parlia/stakehub.go.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| eth/backend.go | Adds logic to check and register the node ID by invoking parlia.GetNodeIDs and AddNodeIDs. |
| consensus/parlia/stakehub.go | Introduces the StakeHub contract interface functions for validator and node ID management. |
04b6082 to
da8bdb9
Compare
a8a1314 to
259fc7c
Compare
2e1fd70 to
5f6f7fc
Compare
ed5efa0 to
e651fe4
Compare
There was a problem hiding this comment.
LGTM
the SystemContract bytecode matches: bnb-chain/bsc-genesis-contract@3e38d7b
There was a problem hiding this comment.
Pull Request Overview
This PR implements the StakeHub contract interface and integrates node ID management into the consensus engine. It adds new functions for retrieving validators and node IDs, creates a signed transaction for adding node IDs, and updates configurations and upgrade paths to support the StakeHub contract.
- Adds a new file (consensus/parlia/stakehub.go) with functions GetValidators, GetNodeIDs, AddNodeIDs, and GetNodeIDsMap.
- Updates Ethereum configuration files (eth/ethconfig/gen_config.go and config.go) to include a new ValidatorNodeIDsToAdd field.
- Modifies backend shutdown channel usage and integrates Maxwell upgrade configurations in system contracts.
Reviewed Changes
Copilot reviewed 7 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| eth/ethconfig/gen_config.go | Adds ValidatorNodeIDsToAdd field for TOML marshalling and unmarshalling |
| eth/ethconfig/config.go | Incorporates new ValidatorNodeIDsToAdd field into the configuration structure |
| eth/backend.go | Replaces stopReportCh with stopCh and adds a goroutine for node ID registration |
| core/systemcontracts/upgrade.go | Adds Maxwell upgrade configuration for the StakeHub contract |
| core/systemcontracts/maxwell/types.go | Embeds contract code files for Maxwell upgrades |
| consensus/parlia/stakehub.go | Implements the StakeHub contract interface functions and node ID management |
| consensus/parlia/abi.go | Updates the ABI definition for the StakeHub contract interface with new function names |
Files not reviewed (3)
- core/systemcontracts/maxwell/chapel/StakeHubContract: Language not supported
- core/systemcontracts/maxwell/mainnet/StakeHubContract: Language not supported
- core/systemcontracts/maxwell/rialto/StakeHubContract: Language not supported
Comments suppressed due to low confidence (1)
consensus/parlia/abi.go:4117
- Verify that the renaming and type adjustments in the ABI for the addNodeIDs function correctly match the deployed StakeHub contract interface.
"name": "addNodeIDs",
| to := common.HexToAddress(systemcontracts.StakeHubContract) | ||
| hexData := hexutil.Bytes(data) | ||
| hexNonce := hexutil.Uint64(nonce) | ||
| gas, err := p.ethAPI.EstimateGas(context.Background(), ethapi.TransactionArgs{ |
There was a problem hiding this comment.
Consider providing a context with a timeout for the gas estimation call to avoid potential indefinite hangs.
| gas, err := p.ethAPI.EstimateGas(context.Background(), ethapi.TransactionArgs{ | |
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | |
| defer cancel() | |
| gas, err := p.ethAPI.EstimateGas(ctx, ethapi.TransactionArgs{ |
b875312 to
7bcb02e
Compare
|
|
||
| // GetValidators retrieves validators from the StakeHubContract | ||
| // It returns operator addresses, credit addresses, and total length of validators | ||
| func (p *Parlia) GetValidators(blockNumber uint64, offset, limit *big.Int) ([]common.Address, []common.Address, *big.Int, error) { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
Initially, I thought that 1000 might be excessive and could lead to inefficiency, as the contract might return many validators that most of would never be used. |
Add: StakeHub Contract Interface Implementation
Changes
consensus/parlia/stakehub.goto implement the StakeHub contract interfaceGetValidators: Retrieves validators from the StakeHubContractListNodeIDsFor: Retrieves node IDs for given validatorsGetNodeIDs: Returns flattened array of all node IDs for current validatorsAddNodeIDs: Creates signed transaction to add node IDs to the StakeHub contractTechnical Details
ethAPI.Callenode.IDfor node identificationWhy
This implementation provides a clean interface for interacting with the StakeHub contract, handling validator management and node ID registration in a type-safe and maintainable way.