Skip to content
Merged
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
19 changes: 15 additions & 4 deletions pkg/lumera/modules/action_msg/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package action_msg
import (
"context"
"fmt"
"sync"

actiontypes "github.com/LumeraProtocol/lumera/x/action/v1/types"
"github.com/LumeraProtocol/supernode/v2/pkg/lumera/modules/auth"
Expand All @@ -16,6 +17,7 @@ import (
type module struct {
client actiontypes.MsgClient
txHelper *txmod.TxHelper
mu sync.Mutex
}

func newModule(conn *grpc.ClientConn, authmodule auth.Module, txmodule txmod.Module, kr keyring.Keyring, keyName string, chainID string) (Module, error) {
Expand Down Expand Up @@ -49,6 +51,9 @@ func (m *module) RequestAction(ctx context.Context, actionType, metadata, price,
return nil, err
}

m.mu.Lock()
defer m.mu.Unlock()

return m.txHelper.ExecuteTransaction(ctx, func(creator string) (types.Msg, error) {
return createRequestActionMessage(creator, actionType, metadata, price, expirationTime), nil
})
Expand All @@ -59,6 +64,9 @@ func (m *module) FinalizeCascadeAction(ctx context.Context, actionId string, rqI
return nil, err
}

m.mu.Lock()
defer m.mu.Unlock()

return m.txHelper.ExecuteTransaction(ctx, func(creator string) (types.Msg, error) {
return createFinalizeActionMessage(creator, actionId, rqIdsIds)
})
Expand All @@ -68,11 +76,11 @@ func (m *module) SetTxHelperConfig(config *txmod.TxHelperConfig) {
if config == nil {
return
}
m.txHelper.UpdateConfig(config)
}

func (m *module) GetTxHelper() *txmod.TxHelper {
return m.txHelper
m.mu.Lock()
defer m.mu.Unlock()

m.txHelper.UpdateConfig(config)
}

// SimulateFinalizeCascadeAction builds the finalize message and performs a simulation
Expand All @@ -83,6 +91,9 @@ func (m *module) SimulateFinalizeCascadeAction(ctx context.Context, actionId str
return nil, err
}

m.mu.Lock()
defer m.mu.Unlock()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside SimulateFinalizeCascadeAction, we are calling m.txHelper.GetAccountInfo(ctx) and then m.txHelper.GetCreatorAddress().

Note that GetAccountInfo internally calls GetCreatorAddress to look up the account. By calling GetCreatorAddress again explicitly on the next line (to pass creator to createFinalizeActionMessage), we are duplicating the keyring lookup overhead inside the lock.

Since this is running sequentially under a lock, it might be worth optimizing to fetch the address once and reuse it, or just accepting the overhead if it's negligible. Just a small observation.


// Gather account info and creator address
accountInfo, err := m.txHelper.GetAccountInfo(ctx)
if err != nil {
Expand Down
Loading