-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
What This is TSS's RPC Caller Service as described in this doc: https://docs.google.com/document/d/1xcX86-w8lwT_60flCuYBK9X9co-108-5X6D9e5epw0U/edit#heading=h.76emp0zcbvdy Why This service is responsible for handling incoming transaction submission requests from clients and calling RPC (for the very first time) to submit those transactions to the network
- Loading branch information
1 parent
1e7ab45
commit dd833aa
Showing
24 changed files
with
1,122 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package servicesmocks | ||
|
||
import ( | ||
"github.com/stellar/wallet-backend/internal/entities" | ||
"github.com/stellar/wallet-backend/internal/services" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type RPCServiceMock struct { | ||
mock.Mock | ||
} | ||
|
||
var _ services.RPCService = (*RPCServiceMock)(nil) | ||
|
||
func (r *RPCServiceMock) SendTransaction(transactionXdr string) (entities.RPCSendTransactionResult, error) { | ||
args := r.Called(transactionXdr) | ||
return args.Get(0).(entities.RPCSendTransactionResult), args.Error(1) | ||
} | ||
|
||
func (r *RPCServiceMock) GetTransaction(transactionHash string) (entities.RPCGetTransactionResult, error) { | ||
args := r.Called(transactionHash) | ||
return args.Get(0).(entities.RPCGetTransactionResult), args.Error(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package channels | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/alitto/pond" | ||
|
||
"github.com/stellar/go/support/log" | ||
"github.com/stellar/wallet-backend/internal/tss" | ||
"github.com/stellar/wallet-backend/internal/tss/router" | ||
"github.com/stellar/wallet-backend/internal/tss/services" | ||
"github.com/stellar/wallet-backend/internal/tss/store" | ||
) | ||
|
||
type RPCCallerChannelConfigs struct { | ||
TxManager services.TransactionManager | ||
Router router.Router | ||
Store store.Store | ||
MaxBufferSize int | ||
MaxWorkers int | ||
} | ||
|
||
type rpcCallerPool struct { | ||
Pool *pond.WorkerPool | ||
TxManager services.TransactionManager | ||
Router router.Router | ||
Store store.Store | ||
} | ||
|
||
var RPCCallerChannelName = "RPCCallerChannel" | ||
|
||
var _ tss.Channel = (*rpcCallerPool)(nil) | ||
|
||
func NewRPCCallerChannel(cfg RPCCallerChannelConfigs) *rpcCallerPool { | ||
pool := pond.New(cfg.MaxBufferSize, cfg.MaxWorkers, pond.Strategy(pond.Balanced())) | ||
return &rpcCallerPool{ | ||
Pool: pool, | ||
TxManager: cfg.TxManager, | ||
Store: cfg.Store, | ||
Router: cfg.Router, | ||
} | ||
|
||
} | ||
|
||
func (p *rpcCallerPool) Send(payload tss.Payload) { | ||
p.Pool.Submit(func() { | ||
p.Receive(payload) | ||
}) | ||
} | ||
|
||
func (p *rpcCallerPool) Receive(payload tss.Payload) { | ||
|
||
ctx := context.Background() | ||
// Create a new transaction record in the transactions table. | ||
err := p.Store.UpsertTransaction(ctx, payload.WebhookURL, payload.TransactionHash, payload.TransactionXDR, tss.RPCTXStatus{OtherStatus: tss.NewStatus}) | ||
|
||
if err != nil { | ||
log.Errorf("%s: unable to upsert transaction into transactions table: %e", RPCCallerChannelName, err) | ||
return | ||
} | ||
rpcSendResp, err := p.TxManager.BuildAndSubmitTransaction(ctx, RPCCallerChannelName, payload) | ||
|
||
if err != nil { | ||
log.Errorf("%s: unable to sign and submit transaction: %e", RPCCallerChannelName, err) | ||
return | ||
} | ||
payload.RpcSubmitTxResponse = rpcSendResp | ||
err = p.Router.Route(payload) | ||
if err != nil { | ||
log.Errorf("%s: unable to route payload: %e", RPCCallerChannelName, err) | ||
} | ||
} | ||
|
||
func (p *rpcCallerPool) SetRouter(router router.Router) { | ||
p.Router = router | ||
} | ||
|
||
func (p *rpcCallerPool) Stop() { | ||
p.Pool.StopAndWait() | ||
} |
Oops, something went wrong.