Skip to content

Commit

Permalink
chore: add logs around deposits (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
aloknerurkar authored May 16, 2024
1 parent 5266b68 commit cc9c314
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions p2p/pkg/depositmanager/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Store interface {
amount *big.Int,
blockNumber int64,
) error
ClearBalances(windowNumber *big.Int) error
ClearBalances(windowNumber *big.Int) ([]*big.Int, error)
}

type BlockTracker interface {
Expand Down Expand Up @@ -120,10 +120,12 @@ func (dm *DepositManager) Start(ctx context.Context) <-chan struct{} {
return nil
case window := <-dm.windowChan:
windowToClear := new(big.Int).Sub(window.Window, big.NewInt(2))
if err := dm.store.ClearBalances(windowToClear); err != nil {
dm.logger.Error("failed to clear balances", "error", err)
windows, err := dm.store.ClearBalances(windowToClear)
if err != nil {
dm.logger.Error("failed to clear balances", "error", err, "window", windowToClear)
return err
}
dm.logger.Info("cleared balances", "windows", windows)
case bidderReg := <-dm.bidderRegs:
blocksPerWindow, err := dm.getOrSetBlocksPerWindow()
if err != nil {
Expand All @@ -135,6 +137,7 @@ func (dm *DepositManager) Start(ctx context.Context) <-chan struct{} {
if err := dm.store.SetBalance(bidderReg.Bidder, bidderReg.WindowNumber, effectiveStake); err != nil {
return err
}
dm.logger.Info("set balance", "bidder", bidderReg.Bidder, "window", bidderReg.WindowNumber, "amount", effectiveStake)
}
}
})
Expand Down
6 changes: 3 additions & 3 deletions p2p/pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ func (s *Store) GetBalance(bidder common.Address, windowNumber *big.Int) (*big.I
return val.(*big.Int), nil
}

func (s *Store) ClearBalances(windowNumber *big.Int) error {
func (s *Store) ClearBalances(windowNumber *big.Int) ([]*big.Int, error) {
if windowNumber == nil || windowNumber.Cmp(big.NewInt(0)) == -1 {
return nil
return nil, nil
}

s.mu.RLock()
Expand Down Expand Up @@ -180,7 +180,7 @@ func (s *Store) ClearBalances(windowNumber *big.Int) error {
}
s.mu.Unlock()

return nil
return windows, nil
}

func (s *Store) GetBalanceForBlock(
Expand Down
5 changes: 4 additions & 1 deletion p2p/pkg/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,13 @@ func TestStore(t *testing.T) {
}
}

err = st.ClearBalances(big.NewInt(12))
windows, err := st.ClearBalances(big.NewInt(12))
if err != nil {
t.Fatal(err)
}
if len(windows) != 1 {
t.Fatalf("expected 1, got %d", len(windows))
}

for i := 1; i <= 10; i++ {
val, err := st.GetBalanceForBlock(common.HexToAddress("0x123"), big.NewInt(1), int64(i))
Expand Down

0 comments on commit cc9c314

Please sign in to comment.