-
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.
* tables and interfaces for TSS * TSS tables and the channel interface * remove empty lines * update * adding semicolons adding semicolons * moving all migrations to one file * make hash primary key instead of xdr * missing , * remove the index on try_transaction_xdr and add column/index on try_transaction_hash ...also remove outgoing/incoming_status and have one status column * Squashed commit of the following: commit fb807aa Author: gouthamp-stellar <[email protected]> Date: Tue Sep 3 10:28:49 2024 -0700 remove the index on try_transaction_xdr and add column/index on try_transaction_hash ...also remove outgoing/incoming_status and have one status column commit 6fc0dc2 Author: gouthamp-stellar <[email protected]> Date: Tue Sep 3 08:58:46 2024 -0700 missing , commit a9cf4e3 Author: gouthamp-stellar <[email protected]> Date: Tue Sep 3 01:55:23 2024 -0700 make hash primary key instead of xdr commit c0f9d32 Author: gouthamp-stellar <[email protected]> Date: Fri Aug 30 15:18:27 2024 -0700 moving all migrations to one file commit 2de9898 Author: gouthamp-stellar <[email protected]> Date: Fri Aug 30 15:16:53 2024 -0700 adding semicolons adding semicolons commit 373c71a Author: gouthamp-stellar <[email protected]> Date: Fri Aug 30 15:12:24 2024 -0700 update commit 3f9f9f0 Author: gouthamp-stellar <[email protected]> Date: Fri Aug 30 15:12:00 2024 -0700 remove empty lines commit 9920f48 Author: gouthamp-stellar <[email protected]> Date: Fri Aug 30 15:06:40 2024 -0700 TSS tables and the channel interface commit a58d519 Author: gouthamp-stellar <[email protected]> Date: Fri Aug 30 10:55:22 2024 -0700 tables and interfaces for TSS * commit #2 * changing from RpcIngestTxResponse -> RpcGetIngestTxResponse * latest changes * add tests for ValidateOptions * changes based on comments * latest changes based on changes to interface * string -> RPCTXStatus * adding a transaction_builder.go which takes a list of operation xdrs and builds a transaction out of it * moving transaction_service to the utils dir * upper case Channel methods * latest changes * p.txService.NetworkPassPhrase() * last commit before writing unit tests * Making the transaction service more injectible and adding fields to the Payload * typo * typo * Update 2024-08-28.0-tss_transactions.sql * lint errors * go mod tidy * test cases + other changes * remoce unused mocks * error handler service returns errorHandlerService * changes based on comments * lint deadcode error - suppress for now * removed deadcode * changes after comments on transaction service pr * TSS Error Handler Service * removing print statements * Update transaction_service.go * responding to comments * remove commented code * tx service changes * remove comment * remove comment * latest tx service changes * adding a router + utils file * removing println * changed function name * commit #1 * Code() helper function on RPCTXCode * Code() * Delete .env.swp * adding a helpers file * removing BuildTestFeeBumpTransaction * adding to serve.go etc * casing * better test for Send * resolving merge conflicts * removing mockSleep * delete channels/mocks.go * sleep -> time.Sleep * incorporating Daniel's changes + comments * delete files * remove unused code * name change * remove commented code * moving the mocks file inside servicesmocks dir * name changes * refactor * changes to serve.go * checking error on route.Route * check error * merging main * fixing parsesendresp tests * commit changes * merging in changes from eror_handler_service * delete file * changes based on comments * removing test case that is not relevant anymore * changes based on prev pr comments * remove fmt.Println * merge latest error_handler_service branch + small changes * %s -> %w * U -> u * variable for channel name * merge main * typo in desc string * millisecond wait time
- Loading branch information
1 parent
c062ffb
commit 6553fa9
Showing
11 changed files
with
249 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package channels | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/alitto/pond" | ||
"github.com/stellar/go/support/log" | ||
"github.com/stellar/wallet-backend/internal/tss" | ||
tssutils "github.com/stellar/wallet-backend/internal/tss/utils" | ||
"github.com/stellar/wallet-backend/internal/utils" | ||
) | ||
|
||
type WebhookChannelConfigs struct { | ||
HTTPClient utils.HTTPClient | ||
MaxBufferSize int | ||
MaxWorkers int | ||
MaxRetries int | ||
MinWaitBtwnRetriesMS int | ||
} | ||
|
||
type webhookPool struct { | ||
Pool *pond.WorkerPool | ||
HTTPClient utils.HTTPClient | ||
MaxRetries int | ||
MinWaitBtwnRetriesMS int | ||
} | ||
|
||
var WebhookChannelName = "WebhookChannel" | ||
|
||
var _ tss.Channel = (*webhookPool)(nil) | ||
|
||
func NewWebhookChannel(cfg WebhookChannelConfigs) *webhookPool { | ||
pool := pond.New(cfg.MaxBufferSize, cfg.MaxWorkers, pond.Strategy(pond.Balanced())) | ||
return &webhookPool{ | ||
Pool: pool, | ||
HTTPClient: cfg.HTTPClient, | ||
MaxRetries: cfg.MaxRetries, | ||
MinWaitBtwnRetriesMS: cfg.MinWaitBtwnRetriesMS, | ||
} | ||
|
||
} | ||
|
||
func (p *webhookPool) Send(payload tss.Payload) { | ||
p.Pool.Submit(func() { | ||
p.Receive(payload) | ||
}) | ||
} | ||
|
||
func (p *webhookPool) Receive(payload tss.Payload) { | ||
resp := tssutils.PayloadTOTSSResponse(payload) | ||
jsonData, err := json.Marshal(resp) | ||
if err != nil { | ||
log.Errorf("%s: error marshaling payload: %e", WebhookChannelName, err) | ||
return | ||
} | ||
var i int | ||
for i = 0; i < p.MaxRetries; i++ { | ||
resp, err := p.HTTPClient.Post(payload.WebhookURL, "application/json", bytes.NewBuffer(jsonData)) | ||
if err != nil { | ||
log.Errorf("%s: error making POST request to webhook: %e", WebhookChannelName, err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode == http.StatusOK { | ||
return | ||
} | ||
currentBackoff := p.MinWaitBtwnRetriesMS * (1 << i) | ||
time.Sleep(jitter(time.Duration(currentBackoff)) * time.Millisecond) | ||
} | ||
} | ||
|
||
func (p *webhookPool) Stop() { | ||
p.Pool.StopAndWait() | ||
} |
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,55 @@ | ||
package channels | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stellar/wallet-backend/internal/tss" | ||
tssutils "github.com/stellar/wallet-backend/internal/tss/utils" | ||
"github.com/stellar/wallet-backend/internal/utils" | ||
) | ||
|
||
func TestWebhookHandlerServiceChannel(t *testing.T) { | ||
mockHTTPClient := utils.MockHTTPClient{} | ||
cfg := WebhookChannelConfigs{ | ||
HTTPClient: &mockHTTPClient, | ||
MaxBufferSize: 1, | ||
MaxWorkers: 1, | ||
MaxRetries: 3, | ||
MinWaitBtwnRetriesMS: 5, | ||
} | ||
channel := NewWebhookChannel(cfg) | ||
|
||
payload := tss.Payload{} | ||
payload.WebhookURL = "www.stellar.org" | ||
jsonData, _ := json.Marshal(tssutils.PayloadTOTSSResponse(payload)) | ||
|
||
httpResponse1 := &http.Response{ | ||
StatusCode: http.StatusBadGateway, | ||
Body: io.NopCloser(strings.NewReader(`{"result": {"status": "OK"}}`)), | ||
} | ||
|
||
httpResponse2 := &http.Response{ | ||
StatusCode: http.StatusOK, | ||
Body: io.NopCloser(strings.NewReader(`{"result": {"status": "OK"}}`)), | ||
} | ||
|
||
mockHTTPClient. | ||
On("Post", payload.WebhookURL, "application/json", bytes.NewBuffer(jsonData)). | ||
Return(httpResponse1, nil). | ||
Once() | ||
|
||
mockHTTPClient. | ||
On("Post", payload.WebhookURL, "application/json", bytes.NewBuffer(jsonData)). | ||
Return(httpResponse2, nil). | ||
Once() | ||
|
||
channel.Send(payload) | ||
channel.Stop() | ||
|
||
mockHTTPClient.AssertNumberOfCalls(t, "Post", 2) | ||
} |
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