-
Notifications
You must be signed in to change notification settings - Fork 0
Add Action Lock #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Action Lock #235
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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) { | ||
|
|
@@ -49,6 +51,9 @@ func (m *module) RequestAction(ctx context.Context, actionType, metadata, price, | |
| return nil, err | ||
| } | ||
|
|
||
| m.mu.Lock() | ||
mateeullahmalik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| defer m.mu.Unlock() | ||
|
|
||
| return m.txHelper.ExecuteTransaction(ctx, func(creator string) (types.Msg, error) { | ||
| return createRequestActionMessage(creator, actionType, metadata, price, expirationTime), nil | ||
| }) | ||
|
|
@@ -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) | ||
| }) | ||
|
|
@@ -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 | ||
|
|
@@ -83,6 +91,9 @@ func (m *module) SimulateFinalizeCascadeAction(ctx context.Context, actionId str | |
| return nil, err | ||
| } | ||
|
|
||
| m.mu.Lock() | ||
| defer m.mu.Unlock() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inside Note that 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 { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.