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 SingleAddressWallet from coreutils #928

Merged
merged 69 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
b5b539b
all: use single address wallet from coreutils
peterjan Feb 5, 2024
32641ab
wallet: make sure to return the old types for the time being
peterjan Feb 5, 2024
2e79b52
Merge branch 'pj/peer-store' into pj/single-address-wallet
peterjan Feb 5, 2024
0de27fc
Merge branch 'pj/peer-store' into pj/single-address-wallet
peterjan Feb 6, 2024
f33f6b5
internal: upgrade coreutils
peterjan Feb 6, 2024
5b88ac9
internal: subscribe wallet store
peterjan Feb 6, 2024
ddc1131
all: upgrade coreutils
peterjan Feb 14, 2024
3ec50bc
Merge branch 'its-happening' of github.com:SiaFoundation/renterd into…
peterjan Feb 15, 2024
0b10798
Merge branch 'pj/upgrade-coreutils' into pj/single-address-wallet
peterjan Feb 15, 2024
5fec9dc
stores: migrate wallet tables to wallet_infos and wallet_events
peterjan Feb 16, 2024
00a1a3c
Merge branch 'pj/upgrade-coreutils' into pj/single-address-wallet
peterjan Feb 16, 2024
00771dc
store: fix subscriber deadlock
peterjan Feb 16, 2024
2aec884
stores: remove old subscriber code
peterjan Feb 16, 2024
9186202
bus: fix japecheck
peterjan Feb 22, 2024
dee01c3
stores: fix subscriber close
peterjan Feb 22, 2024
7ead5e6
stores: remove CCID
peterjan Feb 22, 2024
b2ac9ea
stores: fix unit tests
peterjan Feb 22, 2024
7643137
Merge branch 'dev' of github.com:SiaFoundation/renterd into pj/single…
peterjan Feb 27, 2024
cfea189
Merge branch 'its-happening' of github.com:SiaFoundation/renterd into…
peterjan Feb 27, 2024
47bec50
testing: fix unit tests
peterjan Feb 27, 2024
76b42f6
stores: fix key length
peterjan Feb 27, 2024
20f2ab6
Merge branch 'its-happening' of github.com:SiaFoundation/renterd into…
peterjan Feb 27, 2024
0bf1f5a
stores: fix key length
peterjan Feb 27, 2024
53b1ebf
testing: fix TestUploadDownloadBasic
peterjan Feb 28, 2024
93b9597
stores: fix TestTypeMerkleProof
peterjan Feb 28, 2024
14043a0
stores: handle TODOs
peterjan Feb 28, 2024
e5b55d4
testing: fix TestEphemeralAccounts
peterjan Feb 28, 2024
014ffc9
stores: record wallet metrics
peterjan Feb 28, 2024
5cd6577
testing: fix deadlock
peterjan Feb 28, 2024
47bcefb
stores: fix TestWalletTransactions
peterjan Feb 28, 2024
7b37f99
testing: skip TestWalletFormUnconfirmed
peterjan Feb 28, 2024
d0bc5ae
bus: add TODO for wallet metrics
peterjan Feb 29, 2024
c5dcbcd
testing: enable TestWallet
peterjan Feb 29, 2024
21064dd
Merge branch 'dev' of github.com:SiaFoundation/renterd into pj/single…
peterjan Feb 29, 2024
6edee81
autopilot: revert ap changes
peterjan Feb 29, 2024
eb35fc9
all: cleanup PR
peterjan Feb 29, 2024
de6345c
stores: use syncer.PeerNotFound
peterjan Feb 29, 2024
aabb47c
Merge branch 'its-happening' of github.com:SiaFoundation/renterd into…
peterjan Feb 29, 2024
751b6dd
node: close chain store
peterjan Feb 29, 2024
89f4335
stores: update newChainSubscriber
peterjan Feb 29, 2024
036839a
Merge branch 'its-happening' of github.com:SiaFoundation/renterd into…
peterjan Mar 5, 2024
23e1ad9
Merge branch 'its-happening' of github.com:SiaFoundation/renterd into…
peterjan Mar 5, 2024
d7922cb
testing: remove TODO
peterjan Mar 6, 2024
f9ff9da
testing: fix TestWalletFormUnconfirmed
peterjan Mar 7, 2024
ec29f86
testing: mine an extra block when funding the cluster
peterjan Mar 7, 2024
8eee325
coreutils: upgrade deps to have wallet logging
peterjan Mar 7, 2024
0ca4490
testing: trigger autopilot until host gets pruned
peterjan Mar 7, 2024
bc2fdae
test: mine extra blocks
peterjan Mar 7, 2024
f5637a5
testing: add logging
peterjan Mar 7, 2024
a35be42
testing: add logging
peterjan Mar 7, 2024
b9e9d20
testing: add logging
peterjan Mar 7, 2024
921c219
testing: fix TestHostPruning NDF
peterjan Mar 7, 2024
afeea3f
Merge branch 'its-happening' into pj/single-address-wallet
peterjan Mar 11, 2024
3b8cc6b
all: implement CR remarks
peterjan Mar 11, 2024
25f4f0e
all: update toolchain and key string
peterjan Mar 12, 2024
0e46f01
stores: implement PR remarks
peterjan Mar 12, 2024
bc1eb41
bus: add missing interfaces
peterjan Mar 12, 2024
24dc421
bus: add missing interfaces
peterjan Mar 12, 2024
92e8214
modules: revert toolchain upgrade
peterjan Mar 12, 2024
0a1f609
alerts: fix TestAlerts
peterjan Mar 12, 2024
6e0a5c1
autopilot: try fix TestHostPruning NDF
peterjan Mar 12, 2024
7f2a8d7
testing: add logging
peterjan Mar 12, 2024
e3ce6e4
all: upgrade coreutils
peterjan Mar 14, 2024
a156e4e
bus: revert alert change
peterjan Mar 14, 2024
80d98b9
internal: add comment
peterjan Mar 14, 2024
b9ae383
stores: pass rev number & filesize from the fce
peterjan Mar 14, 2024
9618fbf
autopilog: fix race
peterjan Mar 14, 2024
8a9ed02
testing: add TestContractApplyChainUpdates
peterjan Mar 15, 2024
1346f09
stores: update processContract
peterjan Mar 15, 2024
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
21 changes: 21 additions & 0 deletions api/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ import (
"go.sia.tech/core/types"
)

type (
// A SiacoinElement is a SiacoinOutput along with its ID.
SiacoinElement struct {
types.SiacoinOutput
ID types.Hash256 `json:"id"`
MaturityHeight uint64 `json:"maturityHeight"`
}

// A Transaction is an on-chain transaction relevant to a particular wallet,
// paired with useful metadata.
Transaction struct {
Raw types.Transaction `json:"raw,omitempty"`
Index types.ChainIndex `json:"index"`
ID types.TransactionID `json:"id"`
Inflow types.Currency `json:"inflow"`
Outflow types.Currency `json:"outflow"`
Timestamp time.Time `json:"timestamp"`
}
)

type (
// WalletFundRequest is the request type for the /wallet/fund endpoint.
WalletFundRequest struct {
Expand Down Expand Up @@ -73,6 +93,7 @@ type (
Spendable types.Currency `json:"spendable"`
Confirmed types.Currency `json:"confirmed"`
Unconfirmed types.Currency `json:"unconfirmed"`
Immature types.Currency `json:"immature"`
}

// WalletSignRequest is the request type for the /wallet/sign endpoint.
Expand Down
23 changes: 10 additions & 13 deletions autopilot/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"go.sia.tech/renterd/build"
"go.sia.tech/renterd/hostdb"
"go.sia.tech/renterd/object"
"go.sia.tech/renterd/wallet"
"go.sia.tech/renterd/webhooks"
"go.sia.tech/renterd/worker"
"go.uber.org/zap"
Expand Down Expand Up @@ -83,7 +82,7 @@ type Bus interface {
// wallet
Wallet(ctx context.Context) (api.WalletResponse, error)
WalletDiscard(ctx context.Context, txn types.Transaction) error
WalletOutputs(ctx context.Context) (resp []wallet.SiacoinElement, err error)
WalletOutputs(ctx context.Context) (resp []api.SiacoinElement, err error)
WalletPending(ctx context.Context) (resp []types.Transaction, err error)
WalletRedistribute(ctx context.Context, outputs int, amount types.Currency) (ids []types.TransactionID, err error)
}
Expand Down Expand Up @@ -240,12 +239,18 @@ func (ap *Autopilot) Run() error {
ap.workers.withWorker(func(w Worker) {
defer ap.logger.Info("autopilot iteration ended")

// log worker id chosen for this maintenance iteration.
workerID, err := w.ID(ap.shutdownCtx)
if err != nil {
ap.logger.Warn("failed to reach worker, err: %v", err)
} else {
ap.logger.Infof("using worker %s for iteration", workerID)
}

// initiate a host scan - no need to be synced or configured for scanning
ap.s.tryUpdateTimeout()
ap.s.tryPerformHostScan(ap.shutdownCtx, w, forceScan)

// reset forceScan
forceScan = false
forceScan = false // reset forceScan

// block until consensus is synced
if synced, blocked, interrupted := ap.blockUntilSynced(ap.ticker.C); !synced {
Expand All @@ -271,14 +276,6 @@ func (ap *Autopilot) Run() error {
return
}

// Log worker id chosen for this maintenance iteration.
workerID, err := w.ID(ap.shutdownCtx)
if err != nil {
ap.logger.Errorf("aborting maintenance, failed to fetch worker id, err: %v", err)
return
}
ap.logger.Infof("using worker %s for iteration", workerID)

// update the loop state
//
// NOTE: it is important this is the first action we perform in this
Expand Down
8 changes: 4 additions & 4 deletions autopilot/contractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
rhpv2 "go.sia.tech/core/rhp/v2"
rhpv3 "go.sia.tech/core/rhp/v3"
"go.sia.tech/core/types"
"go.sia.tech/coreutils/wallet"
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/hostdb"
"go.sia.tech/renterd/wallet"
"go.sia.tech/renterd/worker"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -1425,7 +1425,7 @@ func (c *contractor) renewContract(ctx context.Context, w Worker, ci contractInf
"renterFunds", renterFunds,
"expectedNewStorage", expectedNewStorage,
)
if strings.Contains(err.Error(), wallet.ErrInsufficientBalance.Error()) {
if isErr(err, wallet.ErrNotEnoughFunds) {
return api.ContractMetadata{}, false, err
}
return api.ContractMetadata{}, true, err
Expand Down Expand Up @@ -1508,7 +1508,7 @@ func (c *contractor) refreshContract(ctx context.Context, w Worker, ci contractI
return api.ContractMetadata{}, true, err
}
c.logger.Errorw("refresh failed", zap.Error(err), "hk", hk, "fcid", fcid)
if strings.Contains(err.Error(), wallet.ErrInsufficientBalance.Error()) {
if isErr(err, wallet.ErrNotEnoughFunds) {
return api.ContractMetadata{}, false, err
}
return api.ContractMetadata{}, true, err
Expand Down Expand Up @@ -1572,7 +1572,7 @@ func (c *contractor) formContract(ctx context.Context, w Worker, host hostdb.Hos
if err != nil {
// TODO: keep track of consecutive failures and break at some point
c.logger.Errorw(fmt.Sprintf("contract formation failed, err: %v", err), "hk", hk)
if strings.Contains(err.Error(), wallet.ErrInsufficientBalance.Error()) {
if isErr(err, wallet.ErrNotEnoughFunds) {
return api.ContractMetadata{}, false, err
}
return api.ContractMetadata{}, true, err
Expand Down
2 changes: 1 addition & 1 deletion autopilot/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (m *migrator) performMigrations(p *workerPool) {
// fetch worker id once
id, err := w.ID(ctx)
if err != nil {
m.logger.Errorf("failed to fetch worker id: %v", err)
m.logger.Errorf("failed to reach worker, err: %v", err)
return
}

Expand Down
10 changes: 3 additions & 7 deletions autopilot/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ func (s *scanner) tryPerformHostScan(ctx context.Context, w scanWorker, force bo
s.logger.Infof("%s started", scanType)

s.wg.Add(1)
s.ap.wg.Add(1)
go func(st string) {
defer s.wg.Done()
defer s.ap.wg.Done()

var interrupted bool
for resp := range s.launchScanWorkers(ctx, w, s.launchHostScans()) {
if s.isInterrupted() || s.ap.isStopped() {
interrupted = true
break
}
if resp.err != nil && !strings.Contains(resp.err.Error(), "connection refused") {
Expand All @@ -212,8 +212,7 @@ func (s *scanner) tryPerformHostScan(ctx context.Context, w scanWorker, force bo
hostCfg := s.ap.State().cfg.Hosts
maxDowntime := time.Duration(hostCfg.MaxDowntimeHours) * time.Hour
minRecentScanFailures := hostCfg.MinRecentScanFailures

if !interrupted && maxDowntime > 0 {
if !s.ap.isStopped() && maxDowntime > 0 {
s.logger.Debugf("removing hosts that have been offline for more than %v and have failed at least %d scans", maxDowntime, minRecentScanFailures)
removed, err := s.bus.RemoveOfflineHosts(ctx, minRecentScanFailures, maxDowntime)
if err != nil {
Expand Down Expand Up @@ -253,10 +252,7 @@ func (s *scanner) tryUpdateTimeout() {

func (s *scanner) launchHostScans() chan scanReq {
reqChan := make(chan scanReq, s.scanBatchSize)

s.ap.wg.Add(1)
go func() {
defer s.ap.wg.Done()
defer close(reqChan)

var offset int
Expand Down
4 changes: 2 additions & 2 deletions autopilot/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestScanner(t *testing.T) {
// init new scanner
b := &mockBus{hosts: hosts}
w := &mockWorker{blockChan: make(chan struct{})}
s := newTestScanner(b, w)
s := newTestScanner(b)

// assert it started a host scan
s.tryPerformHostScan(context.Background(), w, false)
Expand Down Expand Up @@ -139,7 +139,7 @@ func (s *scanner) isScanning() bool {
return s.scanning
}

func newTestScanner(b *mockBus, w *mockWorker) *scanner {
func newTestScanner(b *mockBus) *scanner {
ap := &Autopilot{}
ap.shutdownCtx, ap.shutdownCtxCancel = context.WithCancel(context.Background())
return &scanner{
Expand Down
Loading
Loading