Skip to content

Commit

Permalink
Merge pull request #15 from cortze/dev
Browse files Browse the repository at this point in the history
Update README + cleanup tool commands + Add unitary tests
  • Loading branch information
cortze authored Oct 28, 2022
2 parents 96d6e9e + f1dc794 commit ee11a53
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 32 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ run:
$(BIN) $(STATE_ANALYZER_CMD) \
--log-level=${STATE_ANALYZER_LOG_LEVEL} \
--bn-endpoint=${STATE_ANALYZER_BN_ENDPOINT} \
--outfolder=${STATE_ANALYZER_OUTFOLDER} \
--init-slot=${STATE_ANALYZER_INIT_SLOT} \
--final-slot=${STATE_ANALYZER_FINAL_SLOT} \
--validator-indexes=${STATE_ANALYZER_VALIDATOR_INDEXES} \
Expand Down
63 changes: 62 additions & 1 deletion README.md
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!
7 changes: 0 additions & 7 deletions cmd/reward_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ var RewardsCommand = &cli.Command{
Name: "bn-endpoint",
Usage: "beacon node endpoint (to request the BeaconStates)",
},
&cli.StringFlag{
Name: "outfolder",
Usage: "output result folder",
},
&cli.IntFlag{
Name: "init-slot",
Usage: "init slot from where to start",
Expand Down Expand Up @@ -73,9 +69,6 @@ func LaunchRewardsCalculator(c *cli.Context) error {
if !c.IsSet("bn-endpoint") {
return errors.New("bn endpoint not provided")
}
if !c.IsSet("outfolder") {
return errors.New("outputfolder no provided")
}
if !c.IsSet("init-slot") {
return errors.New("final slot not provided")
}
Expand Down
21 changes: 0 additions & 21 deletions launcher.sh

This file was deleted.

5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
83 changes: 83 additions & 0 deletions pkg/fork_metrics/fork_state/state_test.go
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)

}
Loading

0 comments on commit ee11a53

Please sign in to comment.