-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from cortze/dev
Update README + cleanup tool commands + Add unitary tests
- Loading branch information
Showing
8 changed files
with
351 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1 +1,62 @@ | ||
# Eth2 State Analyzer | ||
# Eth CL State Analyzer | ||
|
||
The CL State Analyzer is a go-written client that indexes all validator-related duties and parameters from Ethereum's beaconchain by fetching the CL States from a node (preferable a locally running archival node). | ||
|
||
The client indexes all the validator/epoch related metrics into a set of postgreSQL tables. Which later on can be used to monitor the performance of validators in the beaconchain. | ||
|
||
This tool has been used to power the [pandametrics.xyz](https://pandametrics.xyz/) public dashboard. | ||
|
||
### Prerequisites | ||
To use the tool, the following requirements need to be installed in the machine: | ||
- [go](https://go.dev/doc/install) preferably on its 1.17 version or above. Go also needs to be executable from the terminal. | ||
- PostgreSQL DB | ||
- Access to a Ethereum CL beacon node (preferably an archive node to index the slots faster) | ||
|
||
### Installation | ||
The repository provides a Makefile that will take care of all your problems. | ||
|
||
To compile locally the client, just type the following command at the root of the directory: | ||
``` | ||
make build | ||
``` | ||
|
||
Or if you prefer to install the client locally type: | ||
``` | ||
make install | ||
``` | ||
|
||
### Running the tool | ||
To execute the tool, you can simply modify the `.env` file with your own configuration. The `.env` file first exports all the variables as system environment variables, and then uses them as arguments when calling the tool. | ||
|
||
*Running the tool (configurable in the `.env` file)*: | ||
``` | ||
make run | ||
``` | ||
|
||
*Available Commands*: | ||
``` | ||
COMMANDS: | ||
rewards analyze the Beacon State of a given slot range | ||
help, h Shows a list of commands or help for one command | ||
``` | ||
|
||
*Available Options (configurable in the `.env` file)* | ||
``` | ||
OPTIONS: | ||
--bn-endpoint value beacon node endpoint (to request the BeaconStates) | ||
--init-slot value init slot from where to start (default: 0) | ||
--final-slot value init slot from where to finish (default: 0) | ||
--validator-indexes value json file including the list of validator indexes (leave the json `[]` to index all the existing validators) | ||
--log-level value log level: debug, warn, info, error | ||
--db-url value example: postgresql://beaconchain:beaconchain@localhost:5432/beacon_states | ||
--workers-num value example: 50 (default: 0) | ||
--db-workers-num value example: 50 (default: 0) | ||
--help, -h show help (default: false) | ||
``` | ||
|
||
|
||
# Maintainers | ||
@cortze , @tadahar | ||
|
||
# Contributing | ||
The project is open for everyone to contribute! |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -33,11 +33,14 @@ func main() { | |
app := &cli.App{ | ||
Name: CliName, | ||
Usage: "Tinny client that requests and processes the Beacon State for the slot range defined.", | ||
UsageText: "state-analyzer [commands] [arguments...]", | ||
UsageText: "eth2-state-analyzer [commands] [arguments...]", | ||
Authors: []*cli.Author{ | ||
{ | ||
Name: "Cortze", | ||
Email: "[email protected]", | ||
}, { | ||
Name: "Tdahar", | ||
Email: "[email protected]", | ||
}, | ||
}, | ||
EnableBashCompletion: true, | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package fork_state | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/attestantio/go-eth2-client/spec/altair" | ||
"github.com/attestantio/go-eth2-client/spec/phase0" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestState(t *testing.T) { | ||
|
||
balancesArray := make([]uint64, 0) | ||
balancesArray = append(balancesArray, 34000000000, 31200000000) | ||
validator1 := phase0.Validator{ | ||
EffectiveBalance: 32000000000, | ||
ActivationEpoch: 0, | ||
ExitEpoch: 10000000000, | ||
} | ||
|
||
validator2 := phase0.Validator{ | ||
EffectiveBalance: 31000000000, | ||
ActivationEpoch: 0, | ||
ExitEpoch: 10000000000, | ||
} | ||
|
||
validatorArray := make([]*phase0.Validator, 0) | ||
validatorArray = append(validatorArray, &validator1, &validator2) | ||
|
||
state := ForkStateContentBase{ | ||
Validators: validatorArray, | ||
Balances: balancesArray, | ||
BlockRoots: make([][]byte, 0), | ||
} | ||
state.Setup() | ||
|
||
require.Equal(t, state.TotalActiveBalance, uint64(validator1.EffectiveBalance+validator2.EffectiveBalance)) | ||
|
||
state.Validators = append(state.Validators, &validator1, &validator2) | ||
|
||
state = ForkStateContentBase{ | ||
Validators: validatorArray, | ||
Balances: balancesArray, | ||
BlockRoots: make([][]byte, 0), | ||
} | ||
state.Setup() | ||
attestations := make([]altair.ParticipationFlags, 0) | ||
attestations = append(attestations, altair.ParticipationFlags(7)) | ||
|
||
ProcessAttestations(&state, attestations) | ||
|
||
require.Equal(t, state.AttestingBalance[0], uint64(validator1.EffectiveBalance)) | ||
require.Equal(t, state.AttestingVals[0], true) | ||
require.Equal(t, state.AttestingVals[1], false) | ||
|
||
attestations = append(attestations, altair.ParticipationFlags(7)) | ||
state = ForkStateContentBase{ | ||
Validators: validatorArray, | ||
Balances: balancesArray, | ||
BlockRoots: make([][]byte, 0), | ||
} | ||
state.Setup() | ||
ProcessAttestations(&state, attestations) | ||
|
||
require.Equal(t, state.AttestingBalance[0], uint64(validator1.EffectiveBalance+validator2.EffectiveBalance)) | ||
require.Equal(t, state.AttestingVals[0], true) | ||
require.Equal(t, state.AttestingVals[1], true) | ||
|
||
state = ForkStateContentBase{ | ||
Validators: validatorArray, | ||
Balances: balancesArray, | ||
BlockRoots: make([][]byte, 0), | ||
} | ||
state.Setup() | ||
attestations[1] = altair.ParticipationFlags(6) | ||
ProcessAttestations(&state, attestations) | ||
|
||
// no source attesting | ||
require.Equal(t, state.AttestingBalance[0], uint64(validator1.EffectiveBalance)) | ||
require.Equal(t, state.AttestingVals[0], true) | ||
require.Equal(t, state.AttestingVals[1], true) | ||
|
||
} |
Oops, something went wrong.