Skip to content

Commit

Permalink
Merge pull request #96 from synapsecns/chore/update-terminology-go
Browse files Browse the repository at this point in the history
Add notary manager + origin contract
  • Loading branch information
trajan0x authored Aug 15, 2022
2 parents 1367eec + 4aebbc8 commit 3820e33
Show file tree
Hide file tree
Showing 95 changed files with 21,197 additions and 21,202 deletions.
24 changes: 12 additions & 12 deletions core/agents/notary/notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"
)

// Notary updates the updater.
// Notary updates the origin contract.
type Notary struct {
indexers map[string]indexer.DomainIndexer
producers map[string]AttestationProducer
Expand All @@ -24,17 +24,17 @@ type Notary struct {
//TODO: This should be done in config.
var RefreshInterval = 1 * time.Second

// NewNotary creates a new updater.
// NewNotary creates a new notary.
func NewNotary(ctx context.Context, cfg config.Config) (_ Notary, err error) {
updater := Notary{
notary := Notary{
indexers: make(map[string]indexer.DomainIndexer),
producers: make(map[string]AttestationProducer),
submitters: make(map[string]AttestationSubmitter),
}

updater.signer, err = config.SignerFromConfig(cfg.Signer)
notary.signer, err = config.SignerFromConfig(cfg.Signer)
if err != nil {
return Notary{}, fmt.Errorf("could not create updater: %w", err)
return Notary{}, fmt.Errorf("could not create notary: %w", err)
}

dbType, err := sql.DBTypeFromString(cfg.Database.Type)
Expand All @@ -50,19 +50,19 @@ func NewNotary(ctx context.Context, cfg config.Config) (_ Notary, err error) {
for name, domain := range cfg.Domains {
domainClient, err := evm.NewEVM(ctx, name, domain)
if err != nil {
return Notary{}, fmt.Errorf("could not create updater for: %w", err)
return Notary{}, fmt.Errorf("could not create notary for: %w", err)
}

updater.indexers[name] = indexer.NewDomainIndexer(dbHandle, domainClient, RefreshInterval)
updater.producers[name] = NewAttestationProducer(domainClient, dbHandle, updater.signer, RefreshInterval)
notary.indexers[name] = indexer.NewDomainIndexer(dbHandle, domainClient, RefreshInterval)
notary.producers[name] = NewAttestationProducer(domainClient, dbHandle, notary.signer, RefreshInterval)
// TODO: this needs to be on a separate chain so it'll need to use a different domain client. Config needs to be modified
updater.submitters[name] = NewAttestationSubmitter(domainClient, dbHandle, updater.signer, RefreshInterval)
notary.submitters[name] = NewAttestationSubmitter(domainClient, dbHandle, notary.signer, RefreshInterval)
}

return updater, nil
return notary, nil
}

// Start starts the updater.{.
// Start starts the notary.{.
func (u Notary) Start(ctx context.Context) error {
g, ctx := errgroup.WithContext(ctx)
for i := range u.indexers {
Expand Down Expand Up @@ -91,7 +91,7 @@ func (u Notary) Start(ctx context.Context) error {

err := g.Wait()
if err != nil {
return fmt.Errorf("could not start the updater: %w", err)
return fmt.Errorf("could not start the notary: %w", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion core/agents/notary/notary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (u NotarySuite) TestNotaryE2E() {
encodedTips, err := types.EncodeTips(types.NewTips(big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0)))
Nil(u.T(), err)

tx, err := u.homeContract.Dispatch(auth.TransactOpts, gofakeit.Uint32(), [32]byte{}, gofakeit.Uint32(), encodedTips, []byte(gofakeit.Paragraph(3, 2, 1, " ")))
tx, err := u.originContract.Dispatch(auth.TransactOpts, gofakeit.Uint32(), [32]byte{}, gofakeit.Uint32(), encodedTips, []byte(gofakeit.Paragraph(3, 2, 1, " ")))
Nil(u.T(), err)
u.testBackend.WaitForConfirmation(u.GetTestContext(), tx)

Expand Down
4 changes: 2 additions & 2 deletions core/agents/notary/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// AttestationProducer updates a producer.
// TODO: this needs to become an interface.
type AttestationProducer struct {
// domain allows access to the home contract
// domain allows access to the origin contract
domain domains.DomainClient
// db is the synapse db
db db.SynapseDB
Expand Down Expand Up @@ -72,7 +72,7 @@ func (a AttestationProducer) update(ctx context.Context) error {
return fmt.Errorf("could not find latest root: %w", err)
}

suggestedAttestation, err := a.domain.Home().ProduceAttestation(ctx)
suggestedAttestation, err := a.domain.Origin().ProduceAttestation(ctx)
if errors.Is(err, domains.ErrNoUpdate) {
// no update produced this time
return nil
Expand Down
2 changes: 1 addition & 1 deletion core/agents/notary/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (u NotarySuite) TestUpdateProducer() {
encodedTips, err := types.EncodeTips(types.NewTips(big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0)))
Nil(u.T(), err)

tx, err := u.homeContract.Dispatch(auth.TransactOpts, u.domainClient.Config().DomainID, [32]byte{}, gofakeit.Uint32(), encodedTips, []byte(gofakeit.Paragraph(3, 2, 1, " ")))
tx, err := u.originContract.Dispatch(auth.TransactOpts, u.domainClient.Config().DomainID, [32]byte{}, gofakeit.Uint32(), encodedTips, []byte(gofakeit.Paragraph(3, 2, 1, " ")))
Nil(u.T(), err)
u.testBackend.WaitForConfirmation(u.GetTestContext(), tx)

Expand Down
2 changes: 1 addition & 1 deletion core/agents/notary/submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// AttestationSubmitter submits updates continuously.
type AttestationSubmitter struct {
// domain allows access to the home contract
// domain allows access to the origin contract
domain domains.DomainClient
// db contains the transaction queue legacyDB
db db.SynapseDB
Expand Down
24 changes: 12 additions & 12 deletions core/agents/notary/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/synapsecns/sanguine/core/config"
"github.com/synapsecns/sanguine/core/contracts/attestationcollector"
"github.com/synapsecns/sanguine/core/contracts/home"
"github.com/synapsecns/sanguine/core/contracts/origin"
"github.com/synapsecns/sanguine/core/domains"
"github.com/synapsecns/sanguine/core/domains/evm"
"github.com/synapsecns/sanguine/core/testutil"
Expand All @@ -24,20 +24,20 @@ import (
"time"
)

// NotarySuite tests the updater agent.
// NotarySuite tests the notary agent.
type NotarySuite struct {
*testutils.TestSuite
testBackend backends.TestBackend
deployManager *testutil.DeployManager
homeContract *home.HomeRef
originContract *origin.OriginRef
attestationContract *attestationcollector.AttestationCollectorRef
domainClient domains.DomainClient
// wallet is the wallet used for the signer
wallet wallet.Wallet
signer signer.Signer
}

// NewNotarySuite creates a new updater suite.
// NewNotarySuite creates a new notary suite.
func NewNotarySuite(tb testing.TB) *NotarySuite {
tb.Helper()

Expand All @@ -53,14 +53,14 @@ func (u *NotarySuite) SetupTest() {

u.testBackend = preset.GetRinkeby().Geth(u.GetTestContext(), u.T())
u.deployManager = testutil.NewDeployManager(u.T())
_, u.homeContract = u.deployManager.GetHome(u.GetTestContext(), u.testBackend)
_, u.originContract = u.deployManager.GetOrigin(u.GetTestContext(), u.testBackend)
_, u.attestationContract = u.deployManager.GetAttestationCollector(u.GetTestContext(), u.testBackend)

var err error
u.domainClient, err = evm.NewEVM(u.GetTestContext(), "updater", config.DomainConfig{
u.domainClient, err = evm.NewEVM(u.GetTestContext(), "notary", config.DomainConfig{
DomainID: uint32(u.testBackend.Config().ChainID),
Type: types.EVM.String(),
HomeAddress: u.homeContract.Address().String(),
OriginAddress: u.originContract.Address().String(),
AttesationCollectorAddress: u.attestationContract.Address().String(),
RPCUrl: u.testBackend.RPCAddress(),
})
Expand All @@ -70,22 +70,22 @@ func (u *NotarySuite) SetupTest() {
Nil(u.T(), err)

// fund the signer
_, updaterManager := u.deployManager.GetUpdaterManager(u.GetTestContext(), u.testBackend)
owner, err := updaterManager.Owner(&bind.CallOpts{Context: u.GetTestContext()})
_, notaryManager := u.deployManager.GetNotaryManager(u.GetTestContext(), u.testBackend)
owner, err := notaryManager.Owner(&bind.CallOpts{Context: u.GetTestContext()})
Nil(u.T(), err)

u.signer = localsigner.NewSigner(u.wallet.PrivateKey())
u.testBackend.FundAccount(u.GetTestContext(), u.signer.Address(), *big.NewInt(params.Ether))

auth := u.testBackend.GetTxContext(u.GetTestContext(), &owner)

// set the updater on the update manager
tx, err := updaterManager.SetUpdater(auth.TransactOpts, u.signer.Address())
// set the notary on the notary manager
tx, err := notaryManager.SetNotary(auth.TransactOpts, u.signer.Address())
Nil(u.T(), err)

u.testBackend.WaitForConfirmation(u.GetTestContext(), tx)

// set the updater on the attestation collector
// set the notary on the attestation collector
owner, err = u.attestationContract.Owner(&bind.CallOpts{Context: u.GetTestContext()})
Nil(u.T(), err)

Expand Down
8 changes: 4 additions & 4 deletions core/config/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type DomainConfig struct {
Type string `toml:"Type"`
// RequiredConfirmations is the number of confirmations to way
RequiredConfirmations uint32 `toml:"Confirmations"`
// HomeAddress gets the x app config address
HomeAddress string `toml:"HomeAddress"`
// OriginAddress gets origin contract address
OriginAddress string `toml:"OriginAddress"`
// AttesationCollectorAddress contains the attestation collector address (if present)
AttesationCollectorAddress string `toml:"AttesationCollectorAddress"`
// RPCUrl to use for the chain
Expand All @@ -62,8 +62,8 @@ func (d DomainConfig) IsValid(_ context.Context) (ok bool, err error) {
}

// TODO: we should defer to chain-specific config here for verification
if d.HomeAddress == "" {
return false, fmt.Errorf("field HomeAddress: %w", ErrRequiredField)
if d.OriginAddress == "" {
return false, fmt.Errorf("field OriginAddress: %w", ErrRequiredField)
}

if d.RPCUrl == "" {
Expand Down
4 changes: 2 additions & 2 deletions core/config/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func domainConfigFixture() config.DomainConfig {
DomainID: gofakeit.Uint32(),
Type: types.AllChainTypes()[0].String(),
RequiredConfirmations: gofakeit.Uint32(),
HomeAddress: utils.NewMockAddress().String(),
OriginAddress: utils.NewMockAddress().String(),
RPCUrl: gofakeit.URL(),
}
}
Expand All @@ -38,7 +38,7 @@ func (c ConfigSuite) TestDomainConfigID() {

func (c ConfigSuite) TestXappConfigAddressBlank() {
domainConfig := domainConfigFixture()
domainConfig.HomeAddress = ""
domainConfig.OriginAddress = ""

ok, err := domainConfig.IsValid(c.GetTestContext())
False(c.T(), ok)
Expand Down
Loading

0 comments on commit 3820e33

Please sign in to comment.