Skip to content

Commit

Permalink
wip GC
Browse files Browse the repository at this point in the history
  • Loading branch information
lunfardo314 committed Mar 5, 2025
1 parent 8a74f3e commit 10c974c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
9 changes: 6 additions & 3 deletions core/memdag/memdag.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,24 @@ func (d *MemDAG) AddVertexNoLock(vid *vertex.WrappedTx) {
d.keep = append(d.keep, keepVertexData{vid, time.Now().Add(_vertexTTL())})
}

// purgeGarbageCollectedVertices with global lock
func (d *MemDAG) purgeGarbageCollectedVertices() {
// garbageCollectVertices with global lock
func (d *MemDAG) garbageCollectVertices() (num int) {
d.WithGlobalWriteLock(func() {
for txid, weakp := range d.vertices {
if weakp.Value() == nil {
delete(d.vertices, txid)
num++
}
}
})
return
}

func (d *MemDAG) doMaintenance() {
deleted := d.updateKeepList()
detachDeleted(deleted)
d.purgeGarbageCollectedVertices()
numPurged := d.garbageCollectVertices()
d.Log().Infof("[memdag] removed empty entries: %d, reached TTL: %d", numPurged, len(deleted))
d.purgeCachedStateReaders()
}

Expand Down
8 changes: 6 additions & 2 deletions core/vertex/vid.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,15 +734,19 @@ func (vid *WrappedTx) String() (ret string) {
return
}

func (vid *WrappedTx) SequencerPredecessor() (ret *WrappedTx) {
func (vid *WrappedTx) SequencerPredecessor(reattachBranch func(txid ledger.TransactionID) *WrappedTx) (ret *WrappedTx) {
vid.Unwrap(UnwrapOptions{
Vertex: func(v *Vertex) {
if seqData := v.Tx.SequencerTransactionData(); seqData != nil {
ret = v.Inputs[seqData.SequencerOutputData.ChainConstraint.PredecessorInputIndex]
}
},
DetachedVertex: func(v *DetachedVertex) {
util.Panicf("SequencerPredecessor: can't get predecessor vertex in detached tx %s", vid.IDShortString())
if vid.IsBranchTransaction() {
ret = reattachBranch(v.BranchID)
} else {
util.Panicf("SequencerPredecessor: can't get predecessor vertex in detached tx %s", vid.IDShortString())
}
},
})
return
Expand Down
6 changes: 3 additions & 3 deletions core/vertex/virtual_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func newVirtualBranchTx(br *multistate.BranchData) *VirtualTransaction {

// toDetachedVertex preserves information about all outputs and baseline in the virtualTx
func (v *Vertex) toDetachedVertex() *DetachedVertex {
ret := &DetachedVertex{
Tx: v.Tx,
BranchID: v.BaselineBranch.ID,
ret := &DetachedVertex{Tx: v.Tx}
if v.BaselineBranch != nil {
ret.BranchID = v.BaselineBranch.ID
}
return ret
}
Expand Down
9 changes: 7 additions & 2 deletions sequencer/own_milestones.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func (seq *Sequencer) FutureConeOwnMilestonesOrdered(rootOutput vertex.WrappedOu
continue
case !vid.IsSequencerMilestone():
continue
case !visited.Contains(vid.SequencerPredecessor()):
case !visited.Contains(vid.SequencerPredecessor(func(txid ledger.TransactionID) *vertex.WrappedTx {
return attacher.AttachTxID(txid, seq)
})):
continue
case !ledger.ValidTransactionPace(vid.Timestamp(), targetTs):
continue
Expand Down Expand Up @@ -87,7 +89,10 @@ func (seq *Sequencer) AddOwnMilestone(vid *vertex.WrappedTx) {
since: time.Now(),
}
if vid.IsSequencerMilestone() {
if prev := vid.SequencerPredecessor(); prev != nil {
prev := vid.SequencerPredecessor(func(txid ledger.TransactionID) *vertex.WrappedTx {
return attacher.AttachTxID(txid, seq)
})
if prev != nil {
if prevConsumed, found := seq.ownMilestones[prev]; found {
withTime.consumed.AddAll(prevConsumed.consumed)
}
Expand Down
8 changes: 4 additions & 4 deletions tests/sequencer_pruner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func Test1SequencerPruner(t *testing.T) {
t.Run("idle", func(t *testing.T) {
const (
maxSlots = 20
maxSlots = 100 // 20
)
testData := initWorkflowTest(t, 1, true)
t.Logf("%s", testData.wrk.Info())
Expand Down Expand Up @@ -168,9 +168,9 @@ func TestNSequencersIdlePruner(t *testing.T) {

func Test5SequencersIdlePruner(t *testing.T) {
const (
maxSlots = 500 // 1000
nSequencers = 4 // in addition to bootstrap
runTime = 60 * time.Second // 120 * time.Second
maxSlots = 1000
nSequencers = 4 // in addition to bootstrap
runTime = 120 * time.Second
)
testData := initMultiSequencerTest(t, nSequencers, true)

Expand Down

0 comments on commit 10c974c

Please sign in to comment.