Skip to content

Commit

Permalink
Merge pull request #2400 from synapsecns/master
Browse files Browse the repository at this point in the history
FE release 2024-03-29
  • Loading branch information
aureliusbtc authored Mar 29, 2024
2 parents ba37cc4 + ae858ad commit 102d27d
Show file tree
Hide file tree
Showing 120 changed files with 12,821 additions and 3,229 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
submodules: 'recursive'

# note: after this action is pushed, whatever this ends up being should go back to latest.
- uses: docker://ghcr.io/synapsecns/sanguine/git-changes-action:latest
- uses: docker://ghcr.io/synapsecns/sanguine/git-changes-action:07a4696bbbafbba2d3ad7ee828b4c8adb21b4d20
id: filter_go
with:
github_token: ${{ secrets.WORKFLOW_PAT || secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/goreleaser-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
fetch-depth: 0
submodules: 'recursive'

- uses: docker://ghcr.io/synapsecns/sanguine/git-changes-action:latest
- uses: docker://ghcr.io/synapsecns/sanguine/git-changes-action:07a4696bbbafbba2d3ad7ee828b4c8adb21b4d20
id: filter_go
with:
github_token: ${{ secrets.WORKFLOW_PAT || secrets.GITHUB_TOKEN }}
Expand Down
30 changes: 30 additions & 0 deletions ethergo/submitter/db/mocks/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion ethergo/submitter/db/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"database/sql/driver"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/synapsecns/sanguine/core/dbcommon"
"math/big"
)

// Service is the interface for the tx queue database.
Expand All @@ -34,6 +35,8 @@ type Service interface {
GetNonceStatus(ctx context.Context, fromAddress common.Address, chainID *big.Int, nonce uint64) (status Status, err error)
// GetNonceAttemptsByStatus gets all txs for a given address and chain id with a given status and nonce.
GetNonceAttemptsByStatus(ctx context.Context, fromAddress common.Address, chainID *big.Int, nonce uint64, matchStatuses ...Status) (txs []TX, err error)
// GetChainIDsByStatus gets the distinct chain ids for a given address and status.
GetChainIDsByStatus(ctx context.Context, fromAddress common.Address, matchStatuses ...Status) (chainIDs []*big.Int, err error)
}

// TransactionFunc is a function that can be passed to DBTransaction.
Expand Down
33 changes: 31 additions & 2 deletions ethergo/submitter/db/txdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"database/sql"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/imkira/go-interpol"
Expand All @@ -15,7 +17,6 @@ import (
"github.com/synapsecns/sanguine/ethergo/util"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"math/big"
)

// NewTXStore creates a new transaction store.
Expand Down Expand Up @@ -53,7 +54,7 @@ func (s *Store) MarkAllBeforeOrAtNonceReplacedOrConfirmed(ctx context.Context, s
Where(fmt.Sprintf("%s <= ?", nonceFieldName), nonce).
Where(fmt.Sprintf("`%s` = ?", fromFieldName), signer.String()).
// just in case we're updating a tx already marked as confirmed
Where(fmt.Sprintf("%s IN ?", statusFieldName), []int{int(db.Submitted.Int()), int(db.FailedSubmit.Int())}).
Where(fmt.Sprintf("%s IN ?", statusFieldName), []int{int(db.Pending.Int()), int(db.Stored.Int()), int(db.Submitted.Int()), int(db.FailedSubmit.Int())}).
Updates(map[string]interface{}{statusFieldName: db.ReplacedOrConfirmed.Int()})

if dbTX.Error != nil {
Expand Down Expand Up @@ -353,6 +354,34 @@ func (s *Store) GetNonceAttemptsByStatus(ctx context.Context, fromAddress common
return txs, nil
}

// GetChainIDsByStatus returns the distinct chain ids for a given address and status.
func (s *Store) GetChainIDsByStatus(ctx context.Context, fromAddress common.Address, matchStatuses ...db.Status) (chainIDs []*big.Int, err error) {
chainIDs64 := []uint64{}

inArgs := statusToArgs(matchStatuses...)

query := ETHTX{
From: fromAddress.String(),
}

tx := s.DB().WithContext(ctx).
Model(&ETHTX{}).
Select(chainIDFieldName).
Distinct().
Where(query).
Where(fmt.Sprintf("%s IN ?", statusFieldName), inArgs).
Find(&chainIDs64)
if tx.Error != nil {
return nil, fmt.Errorf("could not get chain ids: %w", tx.Error)
}

for _, chainID64 := range chainIDs64 {
chainIDs = append(chainIDs, new(big.Int).SetUint64(chainID64))
}

return chainIDs, nil
}

// DB gets the database.
func (s Store) DB() *gorm.DB {
return s.db
Expand Down
46 changes: 46 additions & 0 deletions ethergo/submitter/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,49 @@ func (t *TXSubmitterDBSuite) TestGetNonceStatus() {
}
})
}

func (t *TXSubmitterDBSuite) TestGetChainIDsByStatus() {
t.RunOnAllDBs(func(testDB db.Service) {
chainIDToStatus := map[int64]db.Status{
1: db.Pending,
3: db.Stored,
4: db.FailedSubmit,
}
expectedPendingChainIDs := []int64{1}

for _, mockAccount := range t.mockAccounts {
for _, backend := range t.testBackends {
manager := t.managers[backend.GetChainID()]

// create some test transactions
var txs []*types.Transaction
for i := 0; i < 50; i++ {
legacyTx := &types.LegacyTx{
To: &mockAccount.Address,
Value: big.NewInt(0),
Nonce: uint64(i),
}
tx, err := manager.SignTx(types.NewTx(legacyTx), backend.Signer(), mockAccount.PrivateKey)
t.Require().NoError(err)
txs = append(txs, tx)
}

// put the transactions in the database
for _, tx := range txs {
err := testDB.PutTXS(t.GetTestContext(), db.NewTX(tx, chainIDToStatus[backend.GetBigChainID().Int64()], uuid.New().String()))
t.Require().NoError(err)
}
}

// check which chainIDs are stored with pending status
result, err := testDB.GetChainIDsByStatus(t.GetTestContext(), mockAccount.Address, db.Pending)
t.Require().NoError(err)

resultInt64 := make([]int64, len(result))
for i, chainID := range result {
resultInt64[i] = chainID.Int64()
}
t.Equal(expectedPendingChainIDs, resultInt64)
}
})
}
39 changes: 26 additions & 13 deletions ethergo/submitter/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package submitter
import (
"context"
"fmt"
"math/big"
"sync"
"time"

"github.com/ethereum/go-ethereum/core/types"
"github.com/lmittmann/w3"
"github.com/lmittmann/w3/module/eth"
Expand All @@ -12,9 +16,6 @@ import (
"github.com/synapsecns/sanguine/ethergo/submitter/db"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"math/big"
"sync"
"time"
)

// runSelector runs the selector start loop.
Expand Down Expand Up @@ -60,24 +61,36 @@ func (t *txSubmitterImpl) processQueue(parentCtx context.Context) (err error) {
}
}()

// get all the pendingTxes in the queue
pendingTxes, err := t.db.GetTXS(ctx, t.signer.Address(), nil, db.Stored, db.Pending, db.FailedSubmit, db.Submitted)
pendingChainIDs, err := t.db.GetChainIDsByStatus(ctx, t.signer.Address(), db.Stored, db.Pending, db.FailedSubmit, db.Submitted)
if err != nil {
return fmt.Errorf("could not get pendingTxes: %w", err)
return fmt.Errorf("could not get pendingChainIDs: %w", err)
}

// fetch txes into a map by chainid.
sortedTXsByChainID := sortTxesByChainID(pendingTxes)
pendingChainIDs64 := make([]int64, len(pendingChainIDs))
for i, chainID := range pendingChainIDs {
pendingChainIDs64[i] = chainID.Int64()
}
span.SetAttributes(attribute.Int64Slice("pending_chain_ids", pendingChainIDs64))

wg.Add(len(sortedTXsByChainID))
wg.Add(len(pendingChainIDs))

for chainID := range sortedTXsByChainID {
go func(chainID uint64) {
for _, chainID := range pendingChainIDs {
go func(chainID *big.Int) {
defer wg.Done()
err := t.chainPendingQueue(ctx, new(big.Int).SetUint64(chainID), sortedTXsByChainID[chainID])

// get all the pendingTxes in the queue
pendingTxes, err := t.db.GetTXS(ctx, t.signer.Address(), chainID, db.Stored, db.Pending, db.FailedSubmit, db.Submitted)
if err != nil {
span.AddEvent("could not get pendingTxes", trace.WithAttributes(
attribute.String("error", err.Error()), attribute.Int64("chainID", chainID.Int64()),
))
return
}

err = t.chainPendingQueue(ctx, chainID, pendingTxes)
if err != nil {
span.AddEvent("chainPendingQueue error", trace.WithAttributes(
attribute.String("error", err.Error()), attribute.Int64("chainID", int64(chainID))))
attribute.String("error", err.Error()), attribute.Int64("chainID", chainID.Int64())))
}
}(chainID)
}
Expand Down
33 changes: 33 additions & 0 deletions make/scripts/flatten.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# This script flattens Solidity contracts and saves them in ./flattened
# The existing content of ./flattened is removed
# This tool takes both globs and filenames as the list of arguments and flattens everything
# Usage: ./script/sh/flatten.sh contracts/**.sol contracts/client/TestClient.sol <...>

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Check if arguments were supplied
if [ $# -eq 0 ]; then
echo -e "${RED}Error: provide globs/filenames of the contracts to flatten!${NC}"
exit 1
fi

# First, we remove the existing flattened files
rm -rf ./flattened

# Track the amount of flattened files for the final report
count=0
# Then, we iterate over the supplied arguments
# If any argument was a glob, this will iterate over the files it specifies
for var in "$@"; do
# Strip contract name "Abc.sol" from the path
fn=$(basename "$var")
# Flatten the file and save it in ./flattened
# Make sure that flattened contracts base names are unique!
forge flatten "$var" -o "./flattened/$fn"
((++count))
done

echo -e "${GREEN}Files flattened: $count${NC}"
47 changes: 47 additions & 0 deletions packages/contracts-communication/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.0.5](https://github.com/synapsecns/sanguine/compare/contracts-communication@1.0.4...contracts-communication@1.0.5) (2024-03-29)

**Note:** Version bump only for package contracts-communication





## [1.0.4](https://github.com/synapsecns/sanguine/compare/contracts-communication@1.0.3...contracts-communication@1.0.4) (2024-03-29)


### Bug Fixes

* **contracts-communication:** cleanup scripts ([#2394](https://github.com/synapsecns/sanguine/issues/2394)) ([3e1cf27](https://github.com/synapsecns/sanguine/commit/3e1cf27824e4dc9c1ec91a6e560da393a1ccbdbd))





## [1.0.3](https://github.com/synapsecns/sanguine/compare/contracts-communication@1.0.2...contracts-communication@1.0.3) (2024-03-29)


### Bug Fixes

* **contracts-communication:** deploy proxy script ([#2392](https://github.com/synapsecns/sanguine/issues/2392)) ([46b38a6](https://github.com/synapsecns/sanguine/commit/46b38a624a4e753ccc1d8d5a217d4139c2d5ca5f))
* **contracts-communication:** improve `client.getInterchainFee()` ([#2387](https://github.com/synapsecns/sanguine/issues/2387)) ([a01d39d](https://github.com/synapsecns/sanguine/commit/a01d39d8311857376d64c9eb866546fa5701ec29))





## [1.0.2](https://github.com/synapsecns/sanguine/compare/contracts-communication@1.0.1...contracts-communication@1.0.2) (2024-03-28)

**Note:** Version bump only for package contracts-communication





## 1.0.1 (2024-03-28)

**Note:** Version bump only for package contracts-communication
Loading

0 comments on commit 102d27d

Please sign in to comment.