Skip to content

Commit

Permalink
fix: hint
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Feb 14, 2024
1 parent 5b47b14 commit 6b818cf
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 25 deletions.
15 changes: 2 additions & 13 deletions pkg/api/stewardship.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *Service) stewardshipPutHandler(w http.ResponseWriter, r *http.Request)
}

headers := struct {
BatchID []byte `map:"Swarm-Postage-Batch-Id"`
BatchID []byte `map:"Swarm-Postage-Batch-Id" validate:"required"`
}{}
if response := s.mapStructure(r.Header, &headers); response != nil {
response("invalid header params", logger, w)
Expand All @@ -41,18 +41,7 @@ func (s *Service) stewardshipPutHandler(w http.ResponseWriter, r *http.Request)
err error
)

if len(headers.BatchID) == 0 {
logger.Debug("missing postage batch id for re-upload")
batchID, err = s.storer.BatchHint(paths.Address)
if err != nil {
logger.Debug("unable to find old batch for reference", "error", err)
logger.Error(nil, "unable to find old batch for reference")
jsonhttp.NotFound(w, "unable to find old batch for reference, provide new batch id")
return
}
} else {
batchID = headers.BatchID
}
batchID = headers.BatchID
stamper, save, err := s.getStamper(batchID)
if err != nil {
switch {
Expand Down
1 change: 1 addition & 0 deletions pkg/api/stewardship_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestStewardship(t *testing.T) {
Message: http.StatusText(http.StatusOK),
Code: http.StatusOK,
}),
jsonhttptest.WithRequestHeader("Swarm-Postage-Batch-Id", "aa"),
)
if !stewardMock.LastAddress().Equal(addr) {
t.Fatalf("\nhave address: %q\nwant address: %q", stewardMock.LastAddress().String(), addr.String())
Expand Down
2 changes: 1 addition & 1 deletion pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const (
minPaymentThreshold = 2 * refreshRate // minimal accepted payment threshold of full nodes
maxPaymentThreshold = 24 * refreshRate // maximal accepted payment threshold of full nodes
mainnetNetworkID = uint64(1) //
ReserveCapacity = 65536 // 2^14 chunks
ReserveCapacity = 131072 // 2^14 chunks
reserveWakeUpDuration = 5 * time.Minute // time to wait before waking up reserveWorker
reserveTreshold = ReserveCapacity * 5 / 10
reserveMinimumRadius = 0
Expand Down
4 changes: 4 additions & 0 deletions pkg/storer/internal/transaction/mem.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package transaction

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/storer/internal/transaction/mem_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 The Swarm Authors. All rights reserved.
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
6 changes: 3 additions & 3 deletions pkg/storer/internal/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
Package transaction provides transaction support for localstore operations.
All writes to the localstore (both indexstore and chunkstore) must be made using a transaction.
The transaction must be commited for the writes to be stored on the disk.
The transaction must be committed for the writes to be stored on the disk.
Writes to the transaction are cached in memory so that future Reads return the cached entries, or if not available, entries stored on the disk.
The rules of the transction is as follows:
Expand Down Expand Up @@ -84,7 +84,7 @@ type transaction struct {
// were returned from the storage ops or commit. Safest option is to do a defer call immediately after
// creating the transaction.
// Calls made to the transaction are NOT thread-safe.
// Write operations are stored in memory so that future Read operations return what is currently captured in the transaciton.
// Write operations are stored in memory so that future Read operations return what is currently captured in the transaction.
// For example, calling chunkstore.Put twice and then chunkstore.Delete once will cause the chunk to be stored with a refCnt of 1.
// This is important for certain operations like storing the same chunk multiple times in the same transaction with the
// expectation that the refCnt in the chunkstore correctly responds to number of Put calls.
Expand Down Expand Up @@ -134,7 +134,7 @@ func (s *store) ChunkStore() storage.ReadOnlyChunkStore {

// Run creates a new transaction and gives the caller access to the transaction
// in the form of a callback function. After the callback returns, the transaction
// is commited to the disk. See the Transaction method for more details on how transactions operate internally.
// is committed to the disk. See the Transaction method for more details on how transactions operate internally.
func (s *store) Run(ctx context.Context, f func(Store) error) error {
trx, done := s.NewTransaction(ctx)
defer done()
Expand Down
2 changes: 0 additions & 2 deletions pkg/storer/storer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ type UploadStore interface {
DeleteSession(tagID uint64) error
// ListSessions will list all the Sessions currently being tracked.
ListSessions(offset, limit int) ([]SessionInfo, error)
// BatchHint will return the batch ID hint for the chunk reference if known.
BatchHint(swarm.Address) ([]byte, error)
}

// PinStore is a logical component of the storer which deals with pinning
Expand Down
5 changes: 0 additions & 5 deletions pkg/storer/uploadstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,3 @@ func (db *DB) ListSessions(offset, limit int) ([]SessionInfo, error) {

return tags[min(offset, len(tags)):min(offset+limit, len(tags))], nil
}

// BatchHint is the implementation of the UploadStore.BatchHint method.
func (db *DB) BatchHint(address swarm.Address) ([]byte, error) {
return upload.BatchIDForChunk(db.storage.IndexStore(), address)
}

0 comments on commit 6b818cf

Please sign in to comment.