Skip to content

Commit

Permalink
Fix bls proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
alrevuelta committed Dec 14, 2023
1 parent 8713940 commit 82b9234
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
14 changes: 9 additions & 5 deletions oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,12 +840,16 @@ func (or *Oracle) handleBlsCorrectBlockProposal(block SummarizedBlock) {
if block.BlockType != OkPoolProposalBlsKeys {
log.Fatal("Block type is not OkPoolProposalBlsKeys, BlockType: ", block.BlockType)
}
or.increaseAllPendingRewards(block.Reward)
or.state.ProposedBlocks = append(or.state.ProposedBlocks, block)

log.WithFields(log.Fields{
"BlockNumber": block.Block,
"Slot": block.Slot,
"ValidatorIndex": block.ValidatorIndex,
}).Warn("Block proposal was ok but bls keys are not supported, sending rewards to pool")
or.sendRewardToPool(block.Reward)
"Slot": block.Slot,
"Block": block.Block,
"ValIndex": block.ValidatorIndex,
"RewardWei": block.Reward,
"RewardType": block.RewardType.String(),
}).Info("[Reward] From BLS validator. Not supported so just splitting the rewards among all validators")
}

// Handles a manual subscription to the pool, meaning that an event from the smart contract
Expand Down
37 changes: 29 additions & 8 deletions oracle/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1993,9 +1993,15 @@ func Test_handleMissedBlock(t *testing.T) {
}

func Test_handleBlsCorrectBlockProposal_NotSubscribed(t *testing.T) {
oracle := NewOracle(&Config{})
oracle := NewOracle(&Config{
PoolFeesPercentOver10000: 100, // 1%
})

missed := SummarizedBlock{
oracle.addSubscription(888, "0xa", "0xb")
oracle.addSubscription(999, "0xa", "0xb")

blsBlock := SummarizedBlock{
Block: 1,
Slot: uint64(100),
ValidatorIndex: uint64(1),
ValidatorKey: "0x0123456789abcdef0123456789abcdef01234567",
Expand All @@ -2005,13 +2011,28 @@ func Test_handleBlsCorrectBlockProposal_NotSubscribed(t *testing.T) {
WithdrawalAddress: "0x0123456789abcdef0123456789abcdef01234567",
}

oracle.handleBlsCorrectBlockProposal(missed)
oracle.handleBlsCorrectBlockProposal(blsBlock)

// no automatic subscription is produced
require.Equal(t, 0, len(oracle.state.Validators))
// no automatic subscription is produced. The 2 validators are not the BLS ones.
require.Equal(t, 2, len(oracle.state.Validators))

// all rewards go to the pool
require.Equal(t, big.NewInt(100), oracle.state.PoolAccumulatedFees)
require.Equal(t, big.NewInt(2), oracle.state.PoolAccumulatedFees)

// Run reconciliation
err := oracle.RunOffchainReconciliation()
require.NoError(t, err)

require.Equal(t, 1, len(oracle.state.ProposedBlocks))
require.Equal(t, blsBlock, oracle.state.ProposedBlocks[0])

// check all validators rewards. Each one gets a share
require.Equal(t, big.NewInt(49), oracle.state.Validators[888].PendingRewardsWei)
require.Equal(t, big.NewInt(49), oracle.state.Validators[999].PendingRewardsWei)

// The proposer is not tracked
_, exists := oracle.state.Validators[1]
require.False(t, exists)
}

func Test_handleBlsCorrectBlockProposal_Subscribed(t *testing.T) {
Expand All @@ -2034,8 +2055,8 @@ func Test_handleBlsCorrectBlockProposal_Subscribed(t *testing.T) {
// no automatic subscription is produced
require.Equal(t, 1, len(oracle.state.Validators))

// all rewards go to the pool
require.Equal(t, big.NewInt(100), oracle.state.PoolAccumulatedFees)
// all rewards go to that validator. Again, weird case that should not happen
require.Equal(t, big.NewInt(100), oracle.state.Validators[1].PendingRewardsWei)
}

func Test_increaseAllPendingRewards_1(t *testing.T) {
Expand Down

0 comments on commit 82b9234

Please sign in to comment.