Skip to content

Commit

Permalink
stores: handle TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Feb 28, 2024
1 parent 93b9597 commit 14043a0
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 29 deletions.
13 changes: 0 additions & 13 deletions bus/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,6 @@ func (b *bus) consensusAcceptBlock(jc jape.Context) {
return
}

// TODO: should we extend the API with a way to accept multiple blocks at once?
// TODO: should we deprecate this route in favor of /addblocks
if jc.Check("failed to accept block", b.cm.AddBlocks([]types.Block{block})) != nil {
return
}
Expand All @@ -388,7 +386,6 @@ func (b *bus) consensusAcceptBlock(jc jape.Context) {
}

func (b *bus) syncerAddrHandler(jc jape.Context) {
// TODO: have syncer accept contexts
jc.Encode(b.s.Addr())
}

Expand Down Expand Up @@ -419,7 +416,6 @@ func (b *bus) consensusNetworkHandler(jc jape.Context) {
}

func (b *bus) txpoolFeeHandler(jc jape.Context) {
// TODO: have chain manager accept contexts
jc.Encode(b.cm.RecommendedFee())
}

Expand All @@ -433,7 +429,6 @@ func (b *bus) txpoolBroadcastHandler(jc jape.Context) {
return
}

// TODO: should we handle 'known' return value
_, err := b.cm.AddPoolTransactions(txnSet)
if jc.Check("couldn't broadcast transaction set", err) != nil {
return
Expand Down Expand Up @@ -596,8 +591,6 @@ func (b *bus) walletFundHandler(jc jape.Context) {
return
}

// TODO: UnconfirmedParents needs a ctx (be sure to release inputs on err)

jc.Encode(api.WalletFundResponse{
Transaction: txn,
ToSign: toSign,
Expand Down Expand Up @@ -635,7 +628,6 @@ func (b *bus) walletRedistributeHandler(jc jape.Context) {
ids = append(ids, txns[i].ID())
}

// TODO: should we handle 'known' return parameter here
_, err = b.cm.AddPoolTransactions(txns)
if jc.Check("couldn't broadcast the transaction", err) != nil {
b.w.ReleaseInputs(txns...)
Expand Down Expand Up @@ -680,7 +672,6 @@ func (b *bus) walletPrepareFormHandler(jc jape.Context) {

b.w.SignTransaction(&txn, toSign, ExplicitCoveredFields(txn))

// TODO: UnconfirmedParents needs a ctx (be sure to release inputs on err)
jc.Encode(append(b.cm.UnconfirmedParents(txn), txn))
}

Expand Down Expand Up @@ -727,8 +718,6 @@ func (b *bus) walletPrepareRenewHandler(jc jape.Context) {
return
}

// TODO: UnconfirmedParents needs a ctx (be sure to release inputs on err)

jc.Encode(api.WalletPrepareRenewResponse{
ToSign: toSign,
TransactionSet: append(b.cm.UnconfirmedParents(txn), txn),
Expand Down Expand Up @@ -2322,8 +2311,6 @@ func (b *bus) multipartHandlerListPartsPOST(jc jape.Context) {

// ExplicitCoveredFields returns a CoveredFields that covers all elements
// present in txn.
//
// TODO: where should this live
func ExplicitCoveredFields(txn types.Transaction) (cf types.CoveredFields) {
for i := range txn.SiacoinInputs {
cf.SiacoinInputs = append(cf.SiacoinInputs, uint64(i))
Expand Down
4 changes: 2 additions & 2 deletions bus/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func newTestClient(dir string) (*client.Client, func() error, func(context.Conte

// create bus
network, genesis := build.Network()
b, cleanup, _, err := node.NewBus(node.BusConfig{
b, shutdown, _, err := node.NewBus(node.BusConfig{
Bus: config.Bus{
AnnouncementMaxAgeHours: 24 * 7 * 52, // 1 year
Bootstrap: false,
Expand Down Expand Up @@ -103,7 +103,7 @@ func newTestClient(dir string) (*client.Client, func() error, func(context.Conte

shutdownFn := func(ctx context.Context) error {
server.Shutdown(ctx)
return cleanup(ctx)
return shutdown(ctx)
}
return client, serveFn, shutdownFn, nil
}
4 changes: 2 additions & 2 deletions cmd/renterd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,13 @@ func main() {

busAddr, busPassword := cfg.Bus.RemoteAddr, cfg.Bus.RemotePassword
if cfg.Bus.RemoteAddr == "" {
b, fn, _, err := node.NewBus(busCfg, cfg.Directory, getSeed(), logger)
b, shutdown, _, err := node.NewBus(busCfg, cfg.Directory, getSeed(), logger)
if err != nil {
logger.Fatal("failed to create bus, err: " + err.Error())
}
shutdownFns = append(shutdownFns, shutdownFn{
name: "Bus",
fn: fn,
fn: shutdown,
})

mux.sub["/api/bus"] = treeMux{h: auth(b)}
Expand Down
4 changes: 1 addition & 3 deletions internal/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import (
"gorm.io/gorm"
)

// RHP4 TODOs:
// - get rid of dbConsensusInfo
// - get rid of returned chain manager in bus constructor
// TODOs:
// - pass last tip to AddSubscriber
// - all wallet metrics support
// - add UPNP support
Expand Down
6 changes: 3 additions & 3 deletions internal/testing/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func newTestCluster(t *testing.T, opts testClusterOptions) *TestCluster {
tt.OK(err)

// Create bus.
b, bStopFn, cm, err := node.NewBus(busCfg, busDir, wk, logger)
b, bShutdownFn, cm, err := node.NewBus(busCfg, busDir, wk, logger)
tt.OK(err)

busAuth := jape.BasicAuth(busPassword)
Expand All @@ -424,7 +424,7 @@ func newTestCluster(t *testing.T, opts testClusterOptions) *TestCluster {

var busShutdownFns []func(context.Context) error
busShutdownFns = append(busShutdownFns, busServer.Shutdown)
busShutdownFns = append(busShutdownFns, bStopFn)
busShutdownFns = append(busShutdownFns, bShutdownFn)

// Create worker.
w, wShutdownFn, err := node.NewWorker(workerCfg, busClient, wk, logger)
Expand Down Expand Up @@ -535,7 +535,7 @@ func newTestCluster(t *testing.T, opts testClusterOptions) *TestCluster {

// Fund the bus.
if funding {
// TODO: should need the *2 leeway
// TODO: should not need the *2 leeway
cluster.MineBlocks(busCfg.Network.HardforkFoundation.Height + 144*2)
tt.Retry(1000, 100*time.Millisecond, func() error {
if cs, err := busClient.ConsensusState(ctx); err != nil {
Expand Down
37 changes: 33 additions & 4 deletions stores/hostdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"go.sia.tech/coreutils/chain"
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/hostdb"
stypes "go.sia.tech/siad/types"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -992,7 +991,37 @@ func TestSQLHostBlocklistBasic(t *testing.T) {

// TestAnnouncementMaxAge verifies old announcements are ignored.
func TestAnnouncementMaxAge(t *testing.T) {
t.Skip("TODO: rewrite")
db := newTestSQLStore(t, defaultTestSQLStoreConfig)
defer db.Close()

// assert we don't have any announcements
if len(db.cs.announcements) != 0 {
t.Fatal("expected 0 announcements")
}

// fabricate two blocks with announcements, one before the cutoff and one after
b1 := types.Block{
Transactions: []types.Transaction{newTestTransaction(newTestHostAnnouncement("foo.com:1000"))},
Timestamp: time.Now().Add(-db.cs.announcementMaxAge).Add(-time.Second),
}
b2 := types.Block{
Transactions: []types.Transaction{newTestTransaction(newTestHostAnnouncement("foo.com:1001"))},
Timestamp: time.Now().Add(-db.cs.announcementMaxAge).Add(time.Second),
}

// process b1, expect no announcements
db.cs.processChainApplyUpdateHostDB(&chain.ApplyUpdate{Block: b1})
if len(db.cs.announcements) != 0 {
t.Fatal("expected 0 announcements")
}

// process b2, expect 1 announcement
db.cs.processChainApplyUpdateHostDB(&chain.ApplyUpdate{Block: b2})
if len(db.cs.announcements) != 1 {
t.Fatal("expected 1 announcement")
} else if db.cs.announcements[0].HostAnnouncement.NetAddress != "foo.com:1001" {
t.Fatal("unexpected announcement")
}
}

// addTestHosts adds 'n' hosts to the db and returns their keys.
Expand Down Expand Up @@ -1083,6 +1112,6 @@ func newTestHostAnnouncement(na string) (chain.HostAnnouncement, types.PrivateKe
return a, sk
}

func newTestTransaction(ha chain.HostAnnouncement, sk types.PrivateKey) stypes.Transaction {
return stypes.Transaction{ArbitraryData: [][]byte{ha.ToArbitraryData(sk)}}
func newTestTransaction(ha chain.HostAnnouncement, sk types.PrivateKey) types.Transaction {
return types.Transaction{ArbitraryData: [][]byte{ha.ToArbitraryData(sk)}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
DROP TABLE IF EXISTS `siacoin_elements`;
DROP TABLE IF EXISTS `transactions`;

-- drop column
ALTER TABLE `consensus_infos` DROP COLUMN `cc_id`;

-- dbWalletEvent
CREATE TABLE `wallet_events` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
Expand Down
1 change: 0 additions & 1 deletion stores/migrations/mysql/main/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ CREATE TABLE `buffered_slabs` (
CREATE TABLE `consensus_infos` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime(3) DEFAULT NULL,
`cc_id` longblob,
`height` bigint unsigned DEFAULT NULL,
`block_id` longblob,
PRIMARY KEY (`id`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
DROP TABLE IF EXISTS `siacoin_elements`;
DROP TABLE IF EXISTS `transactions`;

-- drop column
ALTER TABLE `consensus_infos` DROP COLUMN `cc_id`;

-- dbWalletEvent
CREATE TABLE `wallet_events` (`id` integer PRIMARY KEY AUTOINCREMENT,`created_at` datetime,`event_id` blob NOT NULL,`inflow` text,`outflow` text,`transaction` text,`maturity_height` integer,`source` text,`timestamp` integer,`height` integer, `block_id` blob);
CREATE UNIQUE INDEX `idx_wallet_events_event_id` ON `wallet_events`(`event_id`);
Expand Down
2 changes: 1 addition & 1 deletion stores/migrations/sqlite/main/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ CREATE INDEX `idx_slices_db_multipart_part_id` ON `slices`(`db_multipart_part_id
CREATE TABLE `host_announcements` (`id` integer PRIMARY KEY AUTOINCREMENT,`created_at` datetime,`host_key` blob NOT NULL,`block_height` integer,`block_id` text,`net_address` text);

-- dbConsensusInfo
CREATE TABLE `consensus_infos` (`id` integer PRIMARY KEY AUTOINCREMENT,`created_at` datetime,`cc_id` blob,`height` integer,`block_id` blob);
CREATE TABLE `consensus_infos` (`id` integer PRIMARY KEY AUTOINCREMENT,`created_at` datetime,`height` integer,`block_id` blob);

-- dbBlocklistEntry
CREATE TABLE `host_blocklist_entries` (`id` integer PRIMARY KEY AUTOINCREMENT,`created_at` datetime,`entry` text NOT NULL UNIQUE);
Expand Down

0 comments on commit 14043a0

Please sign in to comment.