Skip to content

Commit

Permalink
chain: introduce subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Mar 25, 2024
1 parent bb41b25 commit a1ba198
Show file tree
Hide file tree
Showing 22 changed files with 1,297 additions and 1,072 deletions.
2 changes: 2 additions & 0 deletions api/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
ContractStateFailed = "failed"
)

type ContractState string

const (
ContractArchivalReasonHostPruned = "hostpruned"
ContractArchivalReasonRemoved = "removed"
Expand Down
9 changes: 7 additions & 2 deletions bus/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/build"
"go.sia.tech/renterd/bus/client"
"go.sia.tech/renterd/chain"
"go.sia.tech/renterd/hostdb"
"go.sia.tech/renterd/object"
"go.sia.tech/renterd/webhooks"
Expand Down Expand Up @@ -62,6 +63,11 @@ type (
UnconfirmedParents(txn types.Transaction) []types.Transaction
}

// ChainStore stores chain state.
ChainStore interface {
ApplyChainUpdate(ctx context.Context, cu chain.Update) error
}

// A TransactionPool can validate and relay unconfirmed transactions.
TransactionPool interface {
AcceptTransactionSet(txns []types.Transaction) error
Expand Down Expand Up @@ -1770,7 +1776,6 @@ func (b *bus) paramsHandlerUploadGET(jc jape.Context) {

func (b *bus) consensusState() api.ConsensusState {
cs := b.cm.TipState()

var synced bool
if block, ok := b.cm.Block(cs.Index.ID); ok && time.Since(block.Timestamp) < 2*cs.BlockInterval() {
synced = true
Expand Down Expand Up @@ -2396,7 +2401,7 @@ func (b *bus) multipartHandlerListPartsPOST(jc jape.Context) {
}

// New returns a new Bus.
func New(am *alerts.Manager, hm WebhookManager, cm ChainManager, s Syncer, w Wallet, hdb HostDB, as AutopilotStore, ms MetadataStore, ss SettingStore, eas EphemeralAccountStore, mtrcs MetricsStore, l *zap.Logger) (*bus, error) {
func New(am *alerts.Manager, hm WebhookManager, cm ChainManager, s Syncer, w Wallet, hdb HostDB, as AutopilotStore, cs ChainStore, ms MetadataStore, ss SettingStore, eas EphemeralAccountStore, mtrcs MetricsStore, l *zap.Logger) (*bus, error) {
b := &bus{
alerts: alerts.WithOrigin(am, "bus"),
alertMgr: am,
Expand Down
2 changes: 1 addition & 1 deletion 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, shutdown, _, 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
21 changes: 21 additions & 0 deletions chain/manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package chain

import (
"go.sia.tech/core/consensus"
"go.sia.tech/core/types"
"go.sia.tech/coreutils/chain"
)

type Manager = chain.Manager

func TestnetZen() (*consensus.Network, types.Block) {
return chain.TestnetZen()
}

func NewDBStore(db chain.DB, n *consensus.Network, genesisBlock types.Block) (_ *chain.DBStore, _ consensus.State, err error) {
return chain.NewDBStore(db, n, genesisBlock)
}

func NewManager(store chain.Store, cs consensus.State) *Manager {
return chain.NewManager(store, cs)
}
Loading

0 comments on commit a1ba198

Please sign in to comment.