Skip to content

Commit

Permalink
Independent eth1 voting (#8811)
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvanloon committed Apr 25, 2021
1 parent cff7dbd commit a45b045
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
2 changes: 2 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ http_archive(

http_archive(
name = "io_bazel_rules_docker",
patch_args = ["-p1"],
patches = ["//third_party:rules_docker_bad_checksum.patch"],
sha256 = "1286175a94c0b1335efe1d75d22ea06e89742557d3fac2a0366f242a6eac6f5a",
strip_prefix = "rules_docker-ba4310833230294fa69b7d6ea1787ac684631a7d",
urls = ["https://github.com/bazelbuild/rules_docker/archive/ba4310833230294fa69b7d6ea1787ac684631a7d.tar.gz"],
Expand Down
31 changes: 11 additions & 20 deletions beacon-chain/rpc/validator/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,28 +229,19 @@ func (vs *Server) eth1DataMajorityVote(ctx context.Context, beaconState iface.Be
return vs.ChainStartFetcher.ChainStartEth1Data(), nil
}

inRangeVotes, err := vs.inRangeVotes(ctx, beaconState, lastBlockByEarliestValidTime.Number, lastBlockByLatestValidTime.Number)
if err != nil {
return nil, err
}
if len(inRangeVotes) == 0 {
if lastBlockDepositCount >= vs.HeadFetcher.HeadETH1Data().DepositCount {
hash, err := vs.Eth1BlockFetcher.BlockHashByHeight(ctx, lastBlockByLatestValidTime.Number)
if err != nil {
log.WithError(err).Error("Could not get hash of last block by latest valid time")
return vs.randomETH1DataVote(ctx)
}
return &ethpb.Eth1Data{
BlockHash: hash.Bytes(),
DepositCount: lastBlockDepositCount,
DepositRoot: lastBlockDepositRoot[:],
}, nil
if lastBlockDepositCount >= vs.HeadFetcher.HeadETH1Data().DepositCount {
hash, err := vs.Eth1BlockFetcher.BlockHashByHeight(ctx, lastBlockByLatestValidTime.Number)
if err != nil {
log.WithError(err).Error("Could not get hash of last block by latest valid time")
return vs.randomETH1DataVote(ctx)
}
return vs.HeadFetcher.HeadETH1Data(), nil
return &ethpb.Eth1Data{
BlockHash: hash.Bytes(),
DepositCount: lastBlockDepositCount,
DepositRoot: lastBlockDepositRoot[:],
}, nil
}

chosenVote := chosenEth1DataMajorityVote(inRangeVotes)
return &chosenVote.data.eth1Data, nil
return vs.HeadFetcher.HeadETH1Data(), nil
}

func (vs *Server) slotStartTime(slot types.Slot) uint64 {
Expand Down
9 changes: 9 additions & 0 deletions beacon-chain/rpc/validator/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
depositCache.InsertDeposit(context.Background(), dc.Deposit, dc.Eth1BlockHeight, dc.Index, depositTrie.Root())

t.Run("choose highest count", func(t *testing.T) {
t.Skip()
p := mockPOW.NewPOWChain().
InsertBlock(50, earliestValidTime, []byte("earliest")).
InsertBlock(51, earliestValidTime+1, []byte("first")).
Expand Down Expand Up @@ -1128,6 +1129,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
})

t.Run("highest count at earliest valid time - choose highest count", func(t *testing.T) {
t.Skip()
p := mockPOW.NewPOWChain().
InsertBlock(50, earliestValidTime, []byte("earliest")).
InsertBlock(52, earliestValidTime+2, []byte("second")).
Expand Down Expand Up @@ -1163,6 +1165,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
})

t.Run("highest count at latest valid time - choose highest count", func(t *testing.T) {
t.Skip()
p := mockPOW.NewPOWChain().
InsertBlock(50, earliestValidTime, []byte("earliest")).
InsertBlock(51, earliestValidTime+1, []byte("first")).
Expand Down Expand Up @@ -1198,6 +1201,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
})

t.Run("highest count before range - choose highest count within range", func(t *testing.T) {
t.Skip()
p := mockPOW.NewPOWChain().
InsertBlock(49, earliestValidTime-1, []byte("before_range")).
InsertBlock(50, earliestValidTime, []byte("earliest")).
Expand Down Expand Up @@ -1234,6 +1238,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
})

t.Run("highest count after range - choose highest count within range", func(t *testing.T) {
t.Skip()
p := mockPOW.NewPOWChain().
InsertBlock(50, earliestValidTime, []byte("earliest")).
InsertBlock(51, earliestValidTime+1, []byte("first")).
Expand Down Expand Up @@ -1270,6 +1275,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
})

t.Run("highest count on unknown block - choose known block with highest count", func(t *testing.T) {
t.Skip()
p := mockPOW.NewPOWChain().
InsertBlock(50, earliestValidTime, []byte("earliest")).
InsertBlock(51, earliestValidTime+1, []byte("first")).
Expand Down Expand Up @@ -1433,6 +1439,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
})

t.Run("same count - choose more recent block", func(t *testing.T) {
t.Skip()
p := mockPOW.NewPOWChain().
InsertBlock(50, earliestValidTime, []byte("earliest")).
InsertBlock(51, earliestValidTime+1, []byte("first")).
Expand Down Expand Up @@ -1468,6 +1475,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
})

t.Run("highest count on block with less deposits - choose another block", func(t *testing.T) {
t.Skip()
p := mockPOW.NewPOWChain().
InsertBlock(50, earliestValidTime, []byte("earliest")).
InsertBlock(51, earliestValidTime+1, []byte("first")).
Expand Down Expand Up @@ -1504,6 +1512,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
})

t.Run("only one block at earliest valid time - choose this block", func(t *testing.T) {
t.Skip()
p := mockPOW.NewPOWChain().InsertBlock(50, earliestValidTime, []byte("earliest"))

beaconState, err := stateV0.InitializeFromProto(&pbp2p.BeaconState{
Expand Down
13 changes: 13 additions & 0 deletions third_party/rules_docker_bad_checksum.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/repositories/go_repositories.bzl b/repositories/go_repositories.bzl
index 58054f7..12e93eb 100644
--- a/repositories/go_repositories.bzl
+++ b/repositories/go_repositories.bzl
@@ -39,7 +39,7 @@ def go_deps():
name = "com_github_google_go_containerregistry",
urls = ["https://api.github.com/repos/google/go-containerregistry/tarball/8a2841911ffee4f6892ca0083e89752fb46c48dd"], # v0.1.4
strip_prefix = "google-go-containerregistry-8a28419",
- sha256 = "60b9a600affa5667bd444019a4e218b7752d8500cfa923c1ac54ce2f88f773e2",
+ sha256 = "cadb09cb5bcbe00688c73d716d1c9e774d6e4959abec4c425a1b995faf33e964",
importpath = "github.com/google/go-containerregistry",
type = "tar.gz",
)

0 comments on commit a45b045

Please sign in to comment.