diff --git a/p2p/pkg/depositmanager/deposit.go b/p2p/pkg/depositmanager/deposit.go index 1f180eec0..fe4397f45 100644 --- a/p2p/pkg/depositmanager/deposit.go +++ b/p2p/pkg/depositmanager/deposit.go @@ -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 { @@ -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 { @@ -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) } } }) diff --git a/p2p/pkg/store/store.go b/p2p/pkg/store/store.go index 6dd142ff3..d6db21054 100644 --- a/p2p/pkg/store/store.go +++ b/p2p/pkg/store/store.go @@ -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() @@ -180,7 +180,7 @@ func (s *Store) ClearBalances(windowNumber *big.Int) error { } s.mu.Unlock() - return nil + return windows, nil } func (s *Store) GetBalanceForBlock( diff --git a/p2p/pkg/store/store_test.go b/p2p/pkg/store/store_test.go index ec469c0ed..58e64fd9a 100644 --- a/p2p/pkg/store/store_test.go +++ b/p2p/pkg/store/store_test.go @@ -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))