Skip to content
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

Omnirpc Multi-Confirmations #163

Merged
merged 23 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
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
21 changes: 1 addition & 20 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ jobs:
restore-keys: |
${{ runner.os }}-go-

- name: authenticate with github for private go modules
uses: fusion-engineering/setup-git-credentials@v2
with:
credentials: https://trajan0x:${{secrets.GIT_TOKEN }}@github.com/

- name: Install Go
uses: actions/setup-go@v2
with:
Expand Down Expand Up @@ -176,10 +171,7 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: authenticate with github for private go modules
uses: fusion-engineering/setup-git-credentials@v2
with:
credentials: https://0xnero:${{secrets.GIT_TOKEN }}@github.com/

- name: Go modules cache
uses: actions/cache@v2
with:
Expand Down Expand Up @@ -217,11 +209,6 @@ jobs:
fetch-depth: 0
submodules: 'recursive'

- name: authenticate with github for private go modules
uses: fusion-engineering/setup-git-credentials@v2
with:
credentials: https://0xnero:${{secrets.GIT_TOKEN }}@github.com/

# workaround for: https://github.com/golangci/golangci-lint-action/issues/479
- name: Setup cache key
run: cp ${{matrix.package}}/go.mod go.mod -v
Expand All @@ -241,7 +228,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# see: https://github.com/golangci/golangci-lint/issues/337#issuecomment-510136513
GOGC: 20
GOPRIVATE: 'GOPRIVATE=github.com/synapsecns/synapse-node'

# check if we need to rerun go generate as a result of solidity changes. Note, this will only run on solidity changes.
check-generation:
Expand Down Expand Up @@ -298,11 +284,6 @@ jobs:
with:
go-version: 1.19

- name: authenticate with github for private go modules
uses: fusion-engineering/setup-git-credentials@v2
with:
credentials: https://0xnero:${{secrets.GIT_TOKEN }}@github.com/

- name: Go modules cache
uses: actions/cache@v2
with:
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,10 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GHCR_DOCKER }}


- name: authenticate with github for private go modules
uses: fusion-engineering/setup-git-credentials@v2
with:
credentials: https://trajan0x:${{secrets.GIT_TOKEN }}@github.com/

- name: Run GoReleaser
run: goreleaser --rm-dist --debug -f ${{matrix.package}}/.goreleaser.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GONOSUM: '.*'
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
GOGC: 20
GOPRIVATE: 'GOPRIVATE=github.com/synapsecns/synapse-node'
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,8 @@ issues:
- path: testutil/*
linters:
- wrapcheck
- path: ethergo/*
linters:
- staticcheck
text: 'SA1019'
exclude-use-default: false
4 changes: 2 additions & 2 deletions agents/agents/notary/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"github.com/synapsecns/sanguine/core/testsuite"
"github.com/synapsecns/sanguine/ethergo/backends"
"github.com/synapsecns/sanguine/ethergo/backends/preset"
"github.com/synapsecns/sanguine/ethergo/chain/chainwatcher"
"github.com/synapsecns/sanguine/ethergo/signer/signer"
"github.com/synapsecns/sanguine/ethergo/signer/signer/localsigner"
"github.com/synapsecns/sanguine/ethergo/signer/wallet"
"github.com/synapsecns/synapse-node/pkg/chainwatcher"
"math/big"
"testing"
"time"
Expand Down Expand Up @@ -58,7 +58,7 @@ func (u *NotarySuite) SetupTest() {

var err error
u.domainClient, err = evm.NewEVM(u.GetTestContext(), "notary", config.DomainConfig{
DomainID: uint32(u.testBackend.Config().ChainID),
DomainID: uint32(u.testBackend.ChainConfig().ChainID.Uint64()),
Type: types.EVM.String(),
OriginAddress: u.originContract.Address().String(),
AttesationCollectorAddress: u.attestationContract.Address().String(),
Expand Down
7 changes: 2 additions & 5 deletions agents/config/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/richardwilkes/toolbox/collection"
"github.com/synapsecns/synapse-node/pkg/common"
)

// DomainConfigs contains a map of name->domain config.
Expand All @@ -14,7 +13,7 @@ type DomainConfigs map[string]DomainConfig
// IsValid validates the domain configs by asserting no two domains appear twice
// it also calls IsValid on each individual DomainConfig.
func (d DomainConfigs) IsValid(ctx context.Context) (ok bool, err error) {
intSet := collection.NewUint32Set()
intSet := collection.NewSet[uint32]()

for _, cfg := range d {
if intSet.Contains(cfg.DomainID) {
Expand All @@ -39,7 +38,7 @@ type DomainConfig struct {
// Type of the chain (e.g. evm)
Type string `toml:"Type"`
// RequiredConfirmations is the number of confirmations to way
RequiredConfirmations uint32 `toml:"Confirmations"`
RequiredConfirmations uint32 `toml:"ConfirmationsThreshold"`
// OriginAddress gets origin contract address
OriginAddress string `toml:"OriginAddress"`
// AttesationCollectorAddress contains the attestation collector address (if present)
Expand Down Expand Up @@ -72,5 +71,3 @@ func (d DomainConfig) IsValid(_ context.Context) (ok bool, err error) {

return true, nil
}

var _ common.Validator = DomainConfig{}
4 changes: 2 additions & 2 deletions agents/config/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
. "github.com/stretchr/testify/assert"
"github.com/synapsecns/sanguine/agents/config"
"github.com/synapsecns/sanguine/agents/types"
"github.com/synapsecns/synapse-node/testutils/utils"
"github.com/synapsecns/sanguine/ethergo/mocks"
)

func domainConfigFixture() config.DomainConfig {
return config.DomainConfig{
DomainID: gofakeit.Uint32(),
Type: types.AllChainTypes()[0].String(),
RequiredConfirmations: gofakeit.Uint32(),
OriginAddress: utils.NewMockAddress().String(),
OriginAddress: mocks.MockAddress().String(),
RPCUrl: gofakeit.URL(),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (a AttestationCollectorSuite) TestAttestationCollectorSuite() {
a.testBackendOrigin.WaitForConfirmation(a.GetTestContext(), tx)

// Create an attestation
localDomain := uint32(a.testBackendOrigin.Config().ChainID)
localDomain := uint32(a.testBackendOrigin.ChainConfig().ChainID.Uint64())
nonce := gofakeit.Uint32()
root := common.BigToHash(new(big.Int).SetUint64(gofakeit.Uint64()))
unsignedAttestation := types.NewAttestation(localDomain, nonce, root)
Expand Down
2 changes: 1 addition & 1 deletion agents/contracts/destination/destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (d DestinationSuite) TestDestinationSuite() {
d.testBackendOrigin.WaitForConfirmation(d.GetTestContext(), tx)

// Create an attestation
localDomain := uint32(d.testBackendOrigin.Config().ChainID)
localDomain := uint32(d.testBackendOrigin.ChainConfig().ChainID.Uint64())
nonce := gofakeit.Uint32()
root := common.BigToHash(new(big.Int).SetUint64(gofakeit.Uint64()))
unsignedAttestation := types.NewAttestation(localDomain, nonce, root)
Expand Down
3 changes: 1 addition & 2 deletions agents/contracts/destination/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/ethereum/go-ethereum/common"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/synapsecns/sanguine/agents/types"
legacyTypes "github.com/synapsecns/synapse-node/pkg/types"
)

// Parser parses events from the destination contract.
Expand Down Expand Up @@ -42,7 +41,7 @@ func (p parserImpl) EventType(log ethTypes.Log) (_ EventType, ok bool) {
return *eventType, true
}
// return an unknown event to avoid cases where user failed to check the event type
return EventType(len(legacyTypes.AllEventTypes()) + 2), false
return EventType(len(topicMap()) + 2), false
}

// ParseAttestationAccepted parses an AttestationAccepted event.
Expand Down
3 changes: 1 addition & 2 deletions agents/contracts/origin/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/ethereum/go-ethereum/common"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/synapsecns/sanguine/agents/types"
legacyTypes "github.com/synapsecns/synapse-node/pkg/types"
)

// Parser parses events from the origin contract.
Expand Down Expand Up @@ -41,7 +40,7 @@ func (p parserImpl) EventType(log ethTypes.Log) (_ EventType, ok bool) {
return *eventType, true
}
// return an unknown event to avoid cases where user failed to check the event type
return EventType(len(legacyTypes.AllEventTypes()) + 2), false
return EventType(len(topicMap()) + 2), false
}

// ParseDispatch parses an update event.
Expand Down
4 changes: 2 additions & 2 deletions agents/db/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/synapsecns/sanguine/agents/db"
"github.com/synapsecns/sanguine/agents/db/datastore/sql/mysql"
"github.com/synapsecns/sanguine/agents/db/datastore/sql/sqlite"
"github.com/synapsecns/sanguine/core"
"github.com/synapsecns/sanguine/core/testsuite"
"github.com/synapsecns/synapse-node/pkg/common"
"gorm.io/gorm/schema"
"os"
"sync"
Expand Down Expand Up @@ -44,7 +44,7 @@ func (t *DBSuite) SetupTest() {

// connString gets the connection string.
func (t *DBSuite) connString(dbname string) string {
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?parseTime=true", common.GetEnv("MYSQL_USER", "root"), os.Getenv("MYSQL_PASSWORD"), common.GetEnv("MYSQL_HOST", "127.0.0.1"), common.GetEnvInt("MYSQL_PORT", 3306), dbname)
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?parseTime=true", core.GetEnv("MYSQL_USER", "root"), os.Getenv("MYSQL_PASSWORD"), core.GetEnv("MYSQL_HOST", "127.0.0.1"), core.GetEnvInt("MYSQL_PORT", 3306), dbname)
}

func (t *DBSuite) setupMysqlDB() {
Expand Down
8 changes: 5 additions & 3 deletions agents/domains/evm/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"github.com/synapsecns/sanguine/agents/contracts/attestationcollector"
"github.com/synapsecns/sanguine/agents/domains"
"github.com/synapsecns/sanguine/agents/types"
"github.com/synapsecns/sanguine/ethergo/chain"
"github.com/synapsecns/sanguine/ethergo/signer/nonce"
"github.com/synapsecns/sanguine/ethergo/signer/signer"
"github.com/synapsecns/synapse-node/pkg/evm"
)

// NewAttestationCollectorContract returns a bound attestation collector contract.
func NewAttestationCollectorContract(ctx context.Context, client evm.Chain, attestationAddress common.Address) (domains.AttestationCollectorContract, error) {
// nolint: staticcheck
func NewAttestationCollectorContract(ctx context.Context, client chain.Chain, attestationAddress common.Address) (domains.AttestationCollectorContract, error) {
boundCountract, err := attestationcollector.NewAttestationCollectorRef(attestationAddress, client)
if err != nil {
return nil, fmt.Errorf("could not create %T: %w", &attestationcollector.AttestationCollectorRef{}, err)
Expand All @@ -32,7 +33,8 @@ type attestationCollectorContract struct {
// contract contains the conract handle
contract *attestationcollector.AttestationCollectorRef
// client contains the evm client
client evm.Chain
//nolint: staticcheck
client chain.Chain
// nonceManager is the nonce manager used for transacting with the chain
nonceManager nonce.Manager
}
Expand Down
7 changes: 4 additions & 3 deletions agents/domains/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/synapsecns/sanguine/agents/config"
"github.com/synapsecns/sanguine/agents/domains"
"github.com/synapsecns/synapse-node/pkg/evm"
"github.com/synapsecns/sanguine/ethergo/chain"
)

type evmClient struct {
Expand All @@ -16,7 +16,8 @@ type evmClient struct {
// config is the config of the evm client
config config.DomainConfig
// client uses the old synapse client for now
client evm.Chain
//nolint: staticcheck
client chain.Chain
// origin contains the origin contract
origin domains.OriginContract
// attestationCollecotr contains the attestation collector contract
Expand All @@ -27,7 +28,7 @@ var _ domains.DomainClient = &evmClient{}

// NewEVM creates a new evm client.
func NewEVM(ctx context.Context, name string, domain config.DomainConfig) (domains.DomainClient, error) {
underlyingClient, err := evm.NewFromURL(ctx, domain.RPCUrl)
underlyingClient, err := chain.NewFromURL(ctx, domain.RPCUrl)
if err != nil {
return nil, fmt.Errorf("could not get evm: %w", err)
}
Expand Down
16 changes: 10 additions & 6 deletions agents/domains/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"github.com/synapsecns/sanguine/agents/domains/evm"
"github.com/synapsecns/sanguine/agents/testutil"
"github.com/synapsecns/sanguine/agents/types"
"github.com/synapsecns/synapse-node/pkg/common"
"github.com/synapsecns/synapse-node/pkg/evm/client/mocks"
"github.com/synapsecns/synapse-node/testutils/utils"
"github.com/synapsecns/sanguine/ethergo/chain/client/mocks"
etherMocks "github.com/synapsecns/sanguine/ethergo/mocks"
"github.com/synapsecns/sanguine/ethergo/util"
"golang.org/x/sync/errgroup"
"math/big"
"os"
"time"
)

Expand Down Expand Up @@ -51,7 +52,7 @@ func (e *RPCSuite) TestFilterLogsMaxAttempts() {
evm.SetMinBackoff(time.Duration(0))

mockFilterer := new(mocks.EVMClient)
contractAddress := utils.NewMockAddress()
contractAddress := etherMocks.MockAddress()

// create a range filterer so we can test the filter logs method
rangeFilter := evm.NewRangeFilter(contractAddress, mockFilterer, big.NewInt(1), big.NewInt(10), 1, true)
Expand All @@ -62,7 +63,7 @@ func (e *RPCSuite) TestFilterLogsMaxAttempts() {
// return an error
Return(nil, errors.New("I'm a test error"))

logInfo, err := rangeFilter.FilterLogs(e.GetTestContext(), &common.Chunk{
logInfo, err := rangeFilter.FilterLogs(e.GetTestContext(), &util.Chunk{
StartBlock: big.NewInt(1),
EndBlock: big.NewInt(10),
})
Expand All @@ -81,7 +82,7 @@ type Dispatch struct {

// GenerateDispatch generates a mock dispatch for testing.
func GenerateDispatch() Dispatch {
newAddress := utils.NewMockAddress().Bytes()
newAddress := etherMocks.MockAddress().Bytes()
var recipient [32]byte

copy(recipient[:], newAddress)
Expand All @@ -103,6 +104,9 @@ func GenerateDispatches(dispatchCount int) (arr []Dispatch) {
}

func (e *RPCSuite) TestFilterer() {
if os.Getenv("CI") != "" {
e.T().Skip("flakes on ci: since this will be replaced by scribe, we can deprecate this")
}
deployHelper := testutil.NewDeployManager(e.T())

deployedContract, handle := deployHelper.GetOrigin(e.GetTestContext(), e.testBackend)
Expand Down
10 changes: 5 additions & 5 deletions agents/domains/evm/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/jpillora/backoff"
"github.com/pkg/errors"
"github.com/synapsecns/synapse-node/pkg/common"
"github.com/synapsecns/sanguine/ethergo/util"
"math/big"
"time"
)
Expand All @@ -19,13 +19,13 @@ type LogInfo struct {
// logs are logs
logs []types.Log
// chunk are chunks
chunk *common.Chunk
chunk *util.Chunk
}

// RangeFilter pre-fetches filter logs into a channel in deterministic order.
type RangeFilter struct {
// iterator is the chunk iterator used for the range
iterator common.ChunkIterator
iterator util.ChunkIterator
// logs is a channel with the filtered ahead logs. This channel is not closed
// and the user can rely on the garbage collection behavior of RangeFilter to remove it.
logs chan *LogInfo
Expand Down Expand Up @@ -53,7 +53,7 @@ var maxBackoff = 30 * time.Second
// NewRangeFilter creates a new filtering interface for a range of blocks. If reverse is not set, block heights are filtered from start->end.
func NewRangeFilter(address ethCommon.Address, filterer bind.ContractFilterer, startBlock, endBlock *big.Int, chunkSize int, reverse bool) *RangeFilter {
return &RangeFilter{
iterator: common.NewChunkIterator(startBlock, endBlock, chunkSize, reverse),
iterator: util.NewChunkIterator(startBlock, endBlock, chunkSize, reverse),
logs: make(chan *LogInfo, bufferSize),
filterer: filterer,
contractAddress: address,
Expand Down Expand Up @@ -91,7 +91,7 @@ func (f *RangeFilter) Start(ctx context.Context) error {

// FilterLogs safely calls FilterLogs with the filtering implementing a backoff in the case of
// rate limiting and respecting context cancellation.
func (f *RangeFilter) FilterLogs(ctx context.Context, chunk *common.Chunk) (*LogInfo, error) {
func (f *RangeFilter) FilterLogs(ctx context.Context, chunk *util.Chunk) (*LogInfo, error) {
b := &backoff.Backoff{
Factor: 2,
Jitter: true,
Expand Down
Loading