Add SlotsPerArchivedPoint flag and a check ()

* Flag

* Service

* Tests

* Tests and comments

* Lint

* Add to usages

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
terence tsao 2020-03-07 00:06:01 +01:00 committed by GitHub
parent 6a2955d43c
commit 054b15bc45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 0 deletions

View File

@ -97,4 +97,11 @@ var (
Usage: "A slasher provider string endpoint. Can either be an grpc server endpoint.",
Value: "127.0.0.1:5000",
}
// SlotsPerArchivedPoint specifies the number of slots between the archived points, to save beacon state in the cold
// section of DB.
SlotsPerArchivedPoint = cli.IntFlag{
Name: "slots-per-archive-point",
Usage: "The slot durations of when an archived state gets saved in the DB.",
Value: 128,
}
)

View File

@ -46,6 +46,7 @@ var appFlags = []cli.Flag{
flags.ArchiveValidatorSetChangesFlag,
flags.ArchiveBlocksFlag,
flags.ArchiveAttestationsFlag,
flags.SlotsPerArchivedPoint,
cmd.BootstrapNode,
cmd.NoDiscovery,
cmd.StaticPeers,

View File

@ -18,6 +18,7 @@ go_library(
"//beacon-chain/state:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/params:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
@ -31,6 +32,7 @@ go_test(
srcs = [
"epoch_boundary_root_test.go",
"replay_test.go",
"service_test.go",
],
embed = [":go_default_library"],
deps = [

View File

@ -4,6 +4,7 @@ import (
"sync"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/shared/params"
)
// State represents a management object that handles the internal
@ -22,3 +23,13 @@ func New(db db.NoHeadAccessDatabase) *State {
epochBoundarySlotToRoot: make(map[uint64][32]byte),
}
}
// This verifies the archive point frequency is valid. It checks the interval
// is a divisor of the number of slots per epoch. This ensures we have at least one
// archive point within range of our state root history when iterating
// backwards. It also ensures the archive points align with hot state summaries
// which makes it quicker to migrate hot to cold.
func verifySlotsPerArchivePoint(slotsPerArchivePoint uint64) bool {
return slotsPerArchivePoint > 0 &&
slotsPerArchivePoint%params.BeaconConfig().SlotsPerEpoch == 0
}

View File

@ -0,0 +1,27 @@
package stategen
import (
"testing"
"github.com/prysmaticlabs/prysm/shared/params"
)
func Test_verifySlotsPerArchivePoint(t *testing.T) {
type tc struct {
input uint64
result bool
}
tests := []tc{
{0, false},
{1, false},
{params.BeaconConfig().SlotsPerEpoch, true},
{params.BeaconConfig().SlotsPerEpoch + 1, false},
{params.BeaconConfig().SlotsPerHistoricalRoot, true},
{params.BeaconConfig().SlotsPerHistoricalRoot + 1, false},
}
for _, tt := range tests {
if got := verifySlotsPerArchivePoint(tt.input); got != tt.result {
t.Errorf("verifySlotsPerArchivePoint(%d) = %v, want %v", tt.input, got, tt.result)
}
}
}

View File

@ -91,6 +91,7 @@ var appHelpFlagGroups = []flagGroup{
flags.HTTPWeb3ProviderFlag,
flags.SetGCPercent,
flags.UnsafeSync,
flags.SlotsPerArchivedPoint,
},
},
{