Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion tapgarden/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ func (m *MintingBatch) Copy() *MintingBatch {
map[string]*Seedling, len(m.Seedlings),
)
for k, v := range m.Seedlings {
batchCopy.Seedlings[k] = v
seedlingCopy := *v
batchCopy.Seedlings[k] = &seedlingCopy
}
}

Expand Down
25 changes: 22 additions & 3 deletions tapgarden/planter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1897,8 +1897,15 @@ func (c *ChainPlanter) gardener() {
//
// TODO(roasbeef): extend the ticker by a certain
// portion?

// Copy the pending batch to prevent potential
// concurrent read/write issues.
var batchCopy *MintingBatch
if c.pendingBatch != nil {
batchCopy = c.pendingBatch.Copy()
}
req.updates <- SeedlingUpdate{
PendingBatch: c.pendingBatch,
PendingBatch: batchCopy,
NewState: MintingStateSeed,
}

Expand Down Expand Up @@ -1929,7 +1936,13 @@ func (c *ChainPlanter) gardener() {
case req := <-c.stateReqs:
switch req.Type() {
case reqTypePendingBatch:
req.Resolve(c.pendingBatch)
// Resolve a copy of the state to prevent
// potential concurrent read/write issues.
if c.pendingBatch == nil {
req.Resolve((*MintingBatch)(nil))
} else {
req.Resolve(c.pendingBatch.Copy())
}

case reqTypeNumActiveBatches:
req.Resolve(len(c.caretakers))
Expand Down Expand Up @@ -2031,7 +2044,13 @@ func (c *ChainPlanter) gardener() {
c.pendingBatch = sealedBatch
}

req.Resolve(c.pendingBatch)
// Resolve a copy of the state to prevent
// potential concurrent read/write issues.
if c.pendingBatch == nil {
req.Resolve((*MintingBatch)(nil))
} else {
req.Resolve(c.pendingBatch.Copy())
}

case reqTypeFinalizeBatch:
if c.pendingBatch == nil {
Expand Down