Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the host's block height when setting an expiry on EA withdrawal messages #912

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions worker/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type (
UploadSector(ctx context.Context, sector *[rhpv2.SectorSize]byte, rev types.FileContractRevision) (types.Hash256, error)
peterjan marked this conversation as resolved.
Show resolved Hide resolved

FetchPriceTable(ctx context.Context, rev *types.FileContractRevision) (hpt hostdb.HostPriceTable, err error)
FetchRevision(ctx context.Context, fetchTimeout time.Duration, blockHeight uint64) (types.FileContractRevision, error)
FetchRevision(ctx context.Context, fetchTimeout time.Duration) (types.FileContractRevision, error)

FundAccount(ctx context.Context, balance types.Currency, rev *types.FileContractRevision) error
SyncAccount(ctx context.Context, rev *types.FileContractRevision) error
Expand Down Expand Up @@ -209,11 +209,7 @@ func (h *host) FetchPriceTable(ctx context.Context, rev *types.FileContractRevis
}

// pay by account
cs, err := h.bus.ConsensusState(ctx)
if err != nil {
return hostdb.HostPriceTable{}, err
}
return fetchPT(h.preparePriceTableAccountPayment(cs.BlockHeight))
return fetchPT(h.preparePriceTableAccountPayment())
}

func (h *host) FundAccount(ctx context.Context, balance types.Currency, rev *types.FileContractRevision) error {
Expand Down Expand Up @@ -296,10 +292,10 @@ func (h *host) SyncAccount(ctx context.Context, rev *types.FileContractRevision)
//
// NOTE: This is the preferred way of paying for a price table since it is
// faster and doesn't require locking a contract.
func (h *host) preparePriceTableAccountPayment(bh uint64) PriceTablePaymentFunc {
func (h *host) preparePriceTableAccountPayment() PriceTablePaymentFunc {
return func(pt rhpv3.HostPriceTable) (rhpv3.PaymentMethod, error) {
account := rhpv3.Account(h.accountKey.PublicKey())
payment := rhpv3.PayByEphemeralAccount(account, pt.UpdatePriceTableCost, bh+defaultWithdrawalExpiryBlocks, h.accountKey)
payment := rhpv3.PayByEphemeralAccount(account, pt.UpdatePriceTableCost, pt.HostBlockHeight+defaultWithdrawalExpiryBlocks, h.accountKey)
return &payment, nil
}
}
Expand Down
5 changes: 2 additions & 3 deletions worker/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import (
"context"
"errors"
"testing"
"time"

rhpv2 "go.sia.tech/core/rhp/v2"
"go.sia.tech/core/types"
)

func TestHost(t *testing.T) {
c := newMockContract(types.FileContractID{1})
h := newMockHost(types.PublicKey{1}, newTestHostPriceTable(time.Now()), c)
h := newMockHost(types.PublicKey{1})
h.c = newMockContract(h.hk, types.FileContractID{1})
sector, root := newMockSector()

// upload the sector
Expand Down
2 changes: 1 addition & 1 deletion worker/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ SHARDS:
}

// migrate the shards
err = w.uploadManager.MigrateShards(ctx, s, shardIndices, shards, contractSet, allowed, bh, lockingPriorityUpload, mem)
err = w.uploadManager.UploadShards(ctx, s, shardIndices, shards, contractSet, allowed, bh, lockingPriorityUpload, mem)
if err != nil {
return 0, surchargeApplied, fmt.Errorf("failed to upload slab for migration: %w", err)
}
Expand Down
Loading
Loading