Skip to content

pseudosettle: first-contact allowance anchored to Unix epoch instead of connection time #5530

Description

@mfw78

Context

Bee master, package pkg/settlement/pseudosettle. This is a code-level accounting correctness issue found by reading the settlement logic; it is not environment specific.

Summary

The time-based allowance granted for an incoming refreshment is computed as (now - lastSettlementTime) * refreshRate. On first contact with a peer there is no stored settlement record, so lastSettlementTime defaults to 0 (the Unix epoch), making the allowance now * refreshRate, i.e. the entire Unix epoch scaled by the refresh rate.

Expected behavior

The time-based allowance should reflect the time elapsed since the peer connected, so the first refreshment forgives only the debt accrued over the elapsed connected time.

Actual behavior

The first refreshment from a peer can forgive an effectively unbounded debt (bounded only by the peer's current debt), independent of how long the peer has actually been connected, because the allowance window starts at the Unix epoch rather than the connection time.

Steps to reproduce

  1. Connect a peer and let it accrue debt.
  2. Have the peer send its first pseudosettle refreshment.
  3. Observe that peerAllowance returns min(debt, now*refreshRate) and the full debt is accepted regardless of connection duration, because lastTime.Timestamp defaults to 0 on storage.ErrNotFound in peerAllowance (pkg/settlement/pseudosettle/pseudosettle.go).

Possible solution

Record the connection time per peer in init and anchor the first-contact allowance to it rather than to the epoch, so the initial refreshment only forgives debt accrued over the elapsed connected time. Subsequent settlements are unchanged.

AI Disclosure

  • This issue contains suggestions and text generated by an LLM.
  • I have reviewed the AI generated content thoroughly.
  • I possess the technical expertise to responsibly review the AI generated content mentioned in this issue.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions