Skip to content

Commit

Permalink
fix: move the postage logger under the node logger tree (#4386)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrekucci authored Oct 10, 2023
1 parent 401e24e commit f42feec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func NewBee(
b.p2pService = p2ps
b.p2pHalter = p2ps

post, err := postage.NewService(stamperStore, batchStore, chainID)
post, err := postage.NewService(logger, stamperStore, batchStore, chainID)
if err != nil {
return nil, fmt.Errorf("postage service: %w", err)
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/postage/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"github.com/ethersphere/bee/pkg/storage"
)

// loggerName is the tree path name of the logger for this package.
const loggerName = "postage"

const (
// blockThreshold is used to allow threshold no of blocks to be synced before a
// batch is usable.
Expand Down Expand Up @@ -42,6 +45,7 @@ type Service interface {
// service handles postage batches
// stores the active batches.
type service struct {
logger log.Logger
lock sync.Mutex
store storage.Store
postageStore Storer
Expand All @@ -50,8 +54,9 @@ type service struct {
}

// NewService constructs a new Service.
func NewService(store storage.Store, postageStore Storer, chainID int64) (Service, error) {
func NewService(logger log.Logger, store storage.Store, postageStore Storer, chainID int64) (Service, error) {
s := &service{
logger: logger.WithName(loggerName).Register(),
store: store,
postageStore: postageStore,
chainID: chainID,
Expand Down Expand Up @@ -201,11 +206,10 @@ func (ps *service) HandleStampExpiry(id []byte) {
func (ps *service) SetExpired() error {
ps.lock.Lock()
defer ps.lock.Unlock()
logger := log.NewLogger("node").WithName("postage").Register()
for _, issuer := range ps.issuers {
exists, err := ps.postageStore.Exists(issuer.ID())
if err != nil {
logger.Error(err, "set expired: checking if issuer exists", "id", issuer.ID())
ps.logger.Error(err, "set expired: checking if issuer exists", "id", issuer.ID())
return err
}
issuer.SetExpired(!exists)
Expand Down
7 changes: 4 additions & 3 deletions pkg/postage/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"math/big"
"testing"

"github.com/ethersphere/bee/pkg/log"
"github.com/ethersphere/bee/pkg/postage"
pstoremock "github.com/ethersphere/bee/pkg/postage/batchstore/mock"
postagetesting "github.com/ethersphere/bee/pkg/postage/testing"
Expand All @@ -24,7 +25,7 @@ func TestSaveLoad(t *testing.T) {
defer store.Close()
pstore := pstoremock.New()
saved := func(id int64) postage.Service {
ps, err := postage.NewService(store, pstore, id)
ps, err := postage.NewService(log.Noop, store, pstore, id)
if err != nil {
t.Fatal(err)
}
Expand All @@ -40,7 +41,7 @@ func TestSaveLoad(t *testing.T) {
return ps
}
loaded := func(id int64) postage.Service {
ps, err := postage.NewService(store, pstore, id)
ps, err := postage.NewService(log.Noop, store, pstore, id)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -77,7 +78,7 @@ func TestGetStampIssuer(t *testing.T) {
}
validBlockNumber := testChainState.Block - uint64(postage.BlockThreshold+1)
pstore := pstoremock.New(pstoremock.WithChainState(testChainState))
ps, err := postage.NewService(store, pstore, chainID)
ps, err := postage.NewService(log.Noop, store, pstore, chainID)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit f42feec

Please sign in to comment.