Skip to content

Commit

Permalink
Add mutex lock to PenumbraChain and refine function signatures
Browse files Browse the repository at this point in the history
A mutex lock has been introduced in PenumbraChain to ensure thread safety when manipulating the allocations. The function signatures of Acknowledgements, Timeouts, ExportState, and Start methods have also been simplified to exclude unused parameters.
  • Loading branch information
jtieri committed Dec 14, 2023
1 parent 1873c2c commit 2fb32b3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions chain/penumbra/penumbra_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"strconv"
"strings"
"sync"

"cosmossdk.io/math"
"github.com/BurntSushi/toml"
Expand All @@ -34,6 +35,8 @@ type PenumbraChain struct {
numFullNodes int
PenumbraNodes PenumbraNodes
keyring keyring.Keyring

mutex sync.Mutex
}

type PenumbraValidatorDefinition struct {
Expand Down Expand Up @@ -86,12 +89,12 @@ func NewPenumbraChain(log *zap.Logger, testName string, chainConfig ibc.ChainCon
}

// Acknowledgements implements Chain interface.
func (c *PenumbraChain) Acknowledgements(ctx context.Context, height uint64) ([]ibc.PacketAcknowledgement, error) {
func (c *PenumbraChain) Acknowledgements(context.Context, uint64) ([]ibc.PacketAcknowledgement, error) {
panic("implement me")
}

// Timeouts implements Chain interface.
func (c *PenumbraChain) Timeouts(ctx context.Context, height uint64) ([]ibc.PacketTimeout, error) {
func (c *PenumbraChain) Timeouts(context.Context, uint64) ([]ibc.PacketTimeout, error) {
panic("implement me")
}

Expand Down Expand Up @@ -244,7 +247,7 @@ func (c *PenumbraChain) SendIBCTransfer(
}

// ExportState implements Chain interface.
func (c *PenumbraChain) ExportState(ctx context.Context, height int64) (string, error) {
func (c *PenumbraChain) ExportState(context.Context, int64) (string, error) {
panic("implement me")
}

Expand Down Expand Up @@ -342,7 +345,7 @@ type ValidatorWithIntPower struct {

// Start sets up everything needed, (validators, gentx, fullnodes, peering, additional accounts),
// for the chain to start from genesis.
func (c *PenumbraChain) Start(testName string, ctx context.Context, additionalGenesisWallets ...ibc.WalletAmount) error {
func (c *PenumbraChain) Start(_ string, ctx context.Context, additionalGenesisWallets ...ibc.WalletAmount) error {
validators := c.PenumbraNodes[:c.numValidators]
fullnodes := c.PenumbraNodes[c.numValidators:]

Expand Down Expand Up @@ -410,6 +413,9 @@ func (c *PenumbraChain) Start(testName string, ctx context.Context, additionalGe
validatorDefinitions[i] = validatorTemplateDefinition

// self delegation
c.mutex.Lock()
defer c.mutex.Unlock()

allocations = append(allocations,
PenumbraGenesisAppStateAllocation{
Amount: math.NewInt(100_000_000_000),
Expand All @@ -432,11 +438,13 @@ func (c *PenumbraChain) Start(testName string, ctx context.Context, additionalGe
}

for _, wallet := range additionalGenesisWallets {
c.mutex.Lock()
allocations = append(allocations, PenumbraGenesisAppStateAllocation{
Address: wallet.Address,
Denom: wallet.Denom,
Amount: wallet.Amount,
})
c.mutex.Unlock()
}

for _, n := range fullnodes {
Expand Down

0 comments on commit 2fb32b3

Please sign in to comment.