Skip to content

Commit

Permalink
check for panic
Browse files Browse the repository at this point in the history
  • Loading branch information
potuz committed Nov 19, 2021
1 parent 26c61b3 commit dc9a107
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 10 additions & 3 deletions beacon-chain/monitor/process_block.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package monitor

import (
"context"
"fmt"

types "github.com/prysmaticlabs/eth2-types"
Expand All @@ -17,8 +18,15 @@ import (
// 3) An Exit by one of our validators was included
// 4) A Slashing by one of our tracked validators was included
// 5) A Sync Committe Contribution by one of our tracked validators was included
func (s *Service) processBlock(b block.SignedBeaconBlock) {
func (s *Service) processBlock(ctx context.Context, b block.SignedBeaconBlock) {
if b == nil {
return
}

blk := b.Block()
if blk == nil {
return
}

s.processSlashings(blk)
s.processExitsFromBlock(blk)
Expand All @@ -35,7 +43,7 @@ func (s *Service) processBlock(b block.SignedBeaconBlock) {
}

s.processProposedBlock(state, root, blk)
s.processAttestations(state, blk)
s.processAttestations(ctx, state, blk)
}

// processProposedBlock logs the event that one of our tracked validators proposed a block that was included
Expand All @@ -45,7 +53,6 @@ func (s *Service) processProposedBlock(state state.BeaconState, root [32]byte, b
proposedSlotsCounter.WithLabelValues(fmt.Sprintf("%d", blk.ProposerIndex())).Inc()

// update the performance map
// TODO: check if reassignment of structures is a performance hit
balance, err := state.BalanceAtIndex(blk.ProposerIndex())
if err != nil {
log.Error("Could not get balance")
Expand Down
6 changes: 4 additions & 2 deletions beacon-chain/monitor/process_block_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package monitor

import (
"context"
"fmt"
"testing"

Expand Down Expand Up @@ -179,6 +180,7 @@ func TestProcessProposedBlock(t *testing.T) {

func TestProcessBlock_ProposerAndSlashedTrackedVals(t *testing.T) {
hook := logTest.NewGlobal()
ctx := context.Background()
s := setupService(t)
genesis, keys := util.DeterministicGenesisState(t, 64)
genConfig := util.DefaultBlockGenConfig()
Expand All @@ -196,11 +198,11 @@ func TestProcessBlock_ProposerAndSlashedTrackedVals(t *testing.T) {
require.NoError(t, err)
root, err := b.GetBlock().HashTreeRoot()
require.NoError(t, err)
require.NoError(t, s.config.StateGen.SaveState(s.ctx, root, genesis))
require.NoError(t, s.config.StateGen.SaveState(ctx, root, genesis))
wanted1 := fmt.Sprintf("\"Proposed block was included\" BalanceChange=100000000 BlockRoot=%#x NewBalance=32000000000 ParentRoot=0x67a9fe4d0d8d ProposerIndex=15 Slot=1 Version=0 prefix=monitor", bytesutil.Trunc(root[:]))
wanted2 := fmt.Sprintf("\"Proposer slashing was included\" ProposerIndex=%d Root1=0x000100000000 Root2=0x000200000000 SlashingSlot=0 Slot:=1 prefix=monitor", idx)
wrapped := wrapper.WrappedPhase0SignedBeaconBlock(b)
s.processBlock(wrapped)
s.processBlock(ctx, wrapped)
require.LogsContain(t, hook, wanted1)
require.LogsContain(t, hook, wanted2)
}

0 comments on commit dc9a107

Please sign in to comment.