Skip to content

Commit

Permalink
refactor(node): settlements should use task scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
justmoon committed Dec 4, 2023
1 parent 3e3290c commit 9e6d589
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/app-node/src/backend/settlement-schemes/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createActor } from "@dassie/lib-reactive"

import { DassieActorContext } from "../base/types/dassie-base"
import { ManageSettlementSchemeInstancesActor } from "./manage-settlement-scheme-instances"
import { SendOutgoingSettlementsActor } from "./send-outgoing-settlements"

export const SettlementSchemesActor = () =>
createActor((sig) => {
createActor((sig: DassieActorContext) => {
sig.runMap(ManageSettlementSchemeInstancesActor)

sig.runMap(SendOutgoingSettlementsActor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UnreachableCaseError, isFailure } from "@dassie/lib-type-utils"
import { processSettlementPrepare } from "../accounting/functions/process-settlement"
import { Ledger, LedgerStore } from "../accounting/stores/ledger"
import { LedgerId } from "../accounting/types/ledger-id"
import { DassieActorContext } from "../base/types/dassie-base"
import { settlement as logger } from "../logger/instances"
import { SendPeerMessageActor } from "../peer-protocol/actors/send-peer-message"
import { PeersSignal } from "../peer-protocol/computed/peers"
Expand Down Expand Up @@ -104,8 +105,8 @@ export const SendOutgoingSettlementsActor = (reactor: Reactor) => {
const pendingSettlementsMap = reactor.use(PendingSettlementsMap)

return createMapped(reactor, PeersSignal, (peerId) =>
createActor((sig) => {
sig.interval(() => {
createActor((sig: DassieActorContext) => {
function sendOutgoingSettlements() {
const peerState = nodeTable.read().get(peerId)?.peerState

logger.assert(peerState?.id === "peered", "peer state must be 'peered'")
Expand Down Expand Up @@ -196,7 +197,14 @@ export const SendOutgoingSettlementsActor = (reactor: Reactor) => {
logger.warn("failed to prepare outbound settlement", { error })
})
}
}, SETTLEMENT_CHECK_INTERVAL)
}

sig
.task({
handler: sendOutgoingSettlements,
interval: SETTLEMENT_CHECK_INTERVAL,
})
.schedule()
}),
)
}

0 comments on commit 9e6d589

Please sign in to comment.