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

Attestation step 1 #34

Merged
merged 4 commits into from
Jul 7, 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
49 changes: 8 additions & 41 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gogo/protobuf/proto"
"github.com/palomachain/pigeon/attest"
"github.com/palomachain/pigeon/chain"
"github.com/palomachain/pigeon/chain/evm"
"github.com/palomachain/pigeon/chain/paloma"
Expand All @@ -28,10 +27,7 @@ var (

_palomaClient *paloma.Client

_evmClients map[string]evm.Client
_evmProcessors map[string]chain.Processor

_attestRegistry *attest.Registry
_evmFactory *evm.Factory
)

func Relayer() *relayer.Relayer {
Expand All @@ -40,8 +36,7 @@ func Relayer() *relayer.Relayer {
_relayer = relayer.New(
*Config(),
*PalomaClient(),
AttestRegistry(),
GetEvmProcessors(),
EvmFactory(),
)
}
return _relayer
Expand All @@ -63,35 +58,12 @@ func SetConfigPath(path string) {
_configPath = path
}

func GetEvmProcessors() map[string]chain.Processor {
if _evmProcessors == nil {
_evmProcessors = make(map[string]chain.Processor)
}

for chainID, client := range GetEvmClients() {
_evmProcessors[chainID] = evm.NewProcessor(client, chainID)
func EvmFactory() *evm.Factory {
if _evmFactory == nil {
_evmFactory = evm.NewFactory(PalomaClient())
}

return _evmProcessors
}

func GetEvmClients() map[string]evm.Client {
if _evmClients == nil {
_evmClients = make(map[string]evm.Client)
}

config := Config()
for chainName, evmConfig := range config.EVM {
if _, ok := _evmClients[chainName]; ok {
log.WithFields(log.Fields{
"chainName": chainName,
}).Fatal("chain with chainName already registered")
}

_evmClients[chainName] = evm.NewClient(evmConfig, PalomaClient(), chainName)
}

return _evmClients
return _evmFactory
}

func Config() *config.Root {
Expand Down Expand Up @@ -145,13 +117,6 @@ func PalomaClient() *paloma.Client {
return _palomaClient
}

func AttestRegistry() *attest.Registry {
if _attestRegistry == nil {
_attestRegistry = attest.NewRegistry()
}
return _attestRegistry
}

func defaultValue[T comparable](proposedVal T, defaultVal T) T {
var zero T
if proposedVal == zero {
Expand All @@ -173,6 +138,8 @@ func palomaLensClientConfig(palomaConfig config.Paloma) *lens.ChainClientConfig
&consensustypes.MsgAddMessagesSignatures{},
&valsettypes.MsgAddExternalChainInfoForValidator{},
&consensustypes.MsgDeleteJob{},
&consensustypes.MsgAddEvidence{},
&consensustypes.MsgSetPublicAccessData{},
},
},
},
Expand Down
35 changes: 0 additions & 35 deletions attest/attest.go

This file was deleted.

6 changes: 3 additions & 3 deletions chain/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (

ErrNotFound = whoops.String("not found")

EnrichedChainID whoops.Field[string] = "chainID"
EnrichedID whoops.Field[uint64] = "id"
EnrichedItemType whoops.Field[string] = "type"
EnrichedChainReferenceID whoops.Field[string] = "chainReferenceID"
EnrichedID whoops.Field[uint64] = "id"
EnrichedItemType whoops.Field[string] = "type"
)
55 changes: 22 additions & 33 deletions chain/evm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,58 +89,36 @@ func StoredContracts() map[string]StoredContract {
return _contracts
}

//go:generate mockery --name=palomaClienter --inpackage --testonly
type palomaClienter interface {
DeleteJob(ctx context.Context, queueTypeName string, id uint64) error
//go:generate mockery --name=PalomaClienter
type PalomaClienter interface {
AddMessageEvidence(ctx context.Context, queueTypeName string, messageID uint64, proof []byte) error
SetPublicAccessData(ctx context.Context, queueTypeName string, messageID uint64, data []byte) error
QueryGetEVMValsetByID(ctx context.Context, id uint64, chainID string) (*types.Valset, error)
}

type Client struct {
config config.EVM

smartContractAbi abi.ABI

addr ethcommon.Address
keystore *keystore.KeyStore

conn *ethclient.Client

paloma palomaClienter

internalChainID string
}

func NewClient(
cfg config.EVM,
palomaClient palomaClienter,
internalChainID string,
) Client {
client := &Client{
config: cfg,
paloma: palomaClient,
internalChainID: internalChainID,
}

whoops.Assert(client.init())

return *client
paloma PalomaClienter
}

func (c *Client) init() error {
return whoops.Try(func() {
contracts := StoredContracts()
scabi, ok := contracts[smartContractFilename]
if !ok {
whoops.Assert(errors.Unrecoverable(ErrSmartContractNotFound.Format(smartContractFilename)))
}
c.smartContractAbi = scabi.ABI

if !ethcommon.IsHexAddress(c.config.SigningKey) {
whoops.Assert(errors.Unrecoverable(ErrInvalidAddress.Format(c.config.SigningKey)))
}
c.addr = ethcommon.HexToAddress(c.config.SigningKey)

c.keystore = keystore.NewKeyStore(c.config.KeyringDirectory.Path(), keystore.StandardScryptN, keystore.StandardScryptP)
if c.keystore == nil {
c.keystore = keystore.NewKeyStore(c.config.KeyringDirectory.Path(), keystore.StandardScryptN, keystore.StandardScryptP)
}

if !c.keystore.HasAddress(c.addr) {
whoops.Assert(errors.Unrecoverable(ErrAddressNotFoundInKeyStore.Format(c.config.SigningKey, c.config.KeyringDirectory.Path())))
}
Expand Down Expand Up @@ -270,6 +248,10 @@ func (c Client) FilterLogs(ctx context.Context, fq etherum.FilterQuery, currBloc
return filterLogs(ctx, c.conn, fq, currBlockHeight, fn)
}

func (c Client) TransactionByHash(ctx context.Context, txHash common.Hash) (*ethtypes.Transaction, bool, error) {
return c.conn.TransactionByHash(ctx, txHash)
}

//go:generate mockery --name=ethClientToFilterLogs --inpackage --testonly
type ethClientToFilterLogs interface {
FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]etherumtypes.Log, error)
Expand Down Expand Up @@ -361,12 +343,19 @@ func filterLogs(
return false, err
}

func (c Client) ExecuteSmartContract(ctx context.Context, contractAbi abi.ABI, addr common.Address, method string, arguments []any) (*etherumtypes.Transaction, error) {
func (c Client) ExecuteSmartContract(
ctx context.Context,
chainID *big.Int,
contractAbi abi.ABI,
addr common.Address,
method string,
arguments []any,
) (*etherumtypes.Transaction, error) {
return callSmartContract(
ctx,
executeSmartContractIn{
ethClient: c.conn,
chainID: c.config.GetChainID(),
chainID: chainID,
gasAdjustment: c.config.GasAdjustment,
abi: contractAbi,
contract: addr,
Expand Down
Loading