Skip to content

Commit

Permalink
better wording
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonNorthey92 committed Mar 4, 2024
1 parent 4fb3a91 commit e570978
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
24 changes: 17 additions & 7 deletions service/popm/popm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ const (

promSubsystem = "popm_service" // Prometheus

l2KeystonePriorityBufferMaxSize = 10
l2KeystonesMaxSize = 10
)

var log = loggo.GetLogger("popm")
var (
log = loggo.GetLogger("popm")
l2KeystoneRetryTimeout = 15 * time.Second
)

func init() {
loggo.ConfigureLoggers(logLevel)
Expand Down Expand Up @@ -430,7 +433,17 @@ func (m *Miner) mineKnownKeystones(ctx context.Context) {
log.Infof("Received keystone for mining with height %v...", ks.L2BlockNumber)
if err := m.mineKeystone(ctx, &ks); err != nil {
log.Errorf("Failed to mine keystone: %v", err)

// we failed to mine the keystone for some reason, re-add it
// and instruct pop miner to retry after a short period of time
m.AddL2Keystone(ks)

select {
case <-ctx.Done():
return
case <-time.After(l2KeystoneRetryTimeout):
go m.mineKnownKeystones(ctx)
}
}
})
}
Expand All @@ -443,8 +456,6 @@ func (m *Miner) mine(ctx context.Context) {
return
case <-m.mineNowCh:
go m.mineKnownKeystones(ctx)
case <-time.After(15 * time.Second):
go m.mineKnownKeystones(ctx)
}
}
}
Expand Down Expand Up @@ -786,7 +797,6 @@ func (m *Miner) Run(pctx context.Context) error {
return err
}

// Push inserts an L2Keystone, dropping the oldest if full
func (m *Miner) AddL2Keystone(val hemi.L2Keystone) {
serialized := hemi.L2KeystoneAbbreviate(val).Serialize()
key := hex.EncodeToString(serialized[:])
Expand All @@ -799,7 +809,7 @@ func (m *Miner) AddL2Keystone(val hemi.L2Keystone) {
return
}

if len(m.l2Keystones) < l2KeystonePriorityBufferMaxSize {
if len(m.l2Keystones) < l2KeystonesMaxSize {
m.l2Keystones[key] = val
return
}
Expand All @@ -815,7 +825,7 @@ func (m *Miner) AddL2Keystone(val hemi.L2Keystone) {
}

// do not insert an L2Keystone that is older than all of the ones already
// queued
// added
if val.L2BlockNumber < smallestL2BlockNumber {
return
}
Expand Down
8 changes: 4 additions & 4 deletions service/popm/popm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,10 +1050,10 @@ func TestConnectToBFGAndPerformMineALot(t *testing.T) {
messagesExpected := map[protocol.Command]int{
EventConnected: 1,
bfgapi.CmdL2KeystonesRequest: 1,
bfgapi.CmdBitcoinInfoRequest: l2KeystonePriorityBufferMaxSize,
bfgapi.CmdBitcoinBalanceRequest: l2KeystonePriorityBufferMaxSize,
bfgapi.CmdBitcoinUTXOsRequest: l2KeystonePriorityBufferMaxSize,
bfgapi.CmdBitcoinBroadcastRequest: l2KeystonePriorityBufferMaxSize,
bfgapi.CmdBitcoinInfoRequest: l2KeystonesMaxSize,
bfgapi.CmdBitcoinBalanceRequest: l2KeystonesMaxSize,
bfgapi.CmdBitcoinUTXOsRequest: l2KeystonesMaxSize,
bfgapi.CmdBitcoinBroadcastRequest: l2KeystonesMaxSize,
}

for {
Expand Down

0 comments on commit e570978

Please sign in to comment.