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

tmp #118

Draft
wants to merge 111 commits into
base: master
Choose a base branch
from
Draft

tmp #118

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
7f76831
replace QueueBroadcastMsg calls with SyncBroadcastMsg
dbrajovic Jan 10, 2024
655e399
sleep for 1.2s blocktime in between each broadcast to injective
dbrajovic Jan 10, 2024
728d83d
log eth tx opts
dbrajovic Jan 11, 2024
db8738c
estimate gas limit for eth tx
dbrajovic Jan 11, 2024
2ef415e
logs 3
dbrajovic Jan 11, 2024
9f5658d
Merge branch 'master' into fix/account-sequence-mismatch
dbrajovic Jan 11, 2024
b18e662
Merge remote-tracking branch 'origin/fix/estimate-gas' into fix/accou…
dbrajovic Jan 11, 2024
2018269
change method signatures and update logs
dbrajovic Jan 12, 2024
cd212dc
err log
dbrajovic Jan 12, 2024
794fd54
fix decoding val addr
dbrajovic Jan 12, 2024
20de03f
logs
dbrajovic Jan 12, 2024
0e6d3ea
logs 2
dbrajovic Jan 12, 2024
e967990
Revert "sleep for 1.2s blocktime in between each broadcast to injective"
dbrajovic Jan 17, 2024
42cbeaa
Revert "replace QueueBroadcastMsg calls with SyncBroadcastMsg"
dbrajovic Jan 17, 2024
c24e667
sort eth events in broadcast client
dbrajovic Jan 17, 2024
c2267e2
simplify claim sending
dbrajovic Jan 18, 2024
c9f906d
refactor relayEvents
dbrajovic Jan 19, 2024
4261edc
refactor event relaying
dbrajovic Jan 19, 2024
42222e1
refactor
dbrajovic Jan 19, 2024
22ef00a
query last observed eth block and peggy id during orchestrator start up
dbrajovic Jan 22, 2024
4d21cb5
move logs
dbrajovic Jan 22, 2024
22dcb58
relayer: query latest eth valset once
dbrajovic Jan 22, 2024
7b33c3e
move logs
dbrajovic Jan 22, 2024
0d6558b
fix oracle logs to be more accurate
dbrajovic Jan 23, 2024
87df4b0
add descriptive errors
dbrajovic Jan 23, 2024
a6b8d92
logs
dbrajovic Jan 23, 2024
db5a1d0
fix oracle filter
dbrajovic Jan 23, 2024
cdd1ae7
bump sdk-go to v1.50.0
dbrajovic Jan 23, 2024
a12b06a
bump cosmos-sdk to v0.47.3-inj-9
dbrajovic Jan 23, 2024
b9e7aa2
bump wasmd version to v0.45.0-inj
dbrajovic Jan 23, 2024
66eacde
init tendermint client for load balanced connection
dbrajovic Jan 24, 2024
77414bd
separate query client impl
dbrajovic Jan 24, 2024
09df953
replace new impl at call site
dbrajovic Jan 24, 2024
fa12054
fix log
dbrajovic Jan 24, 2024
c0606e8
remove unused field
dbrajovic Jan 24, 2024
9bf4755
refactor peggy query and broadcast clients
dbrajovic Jan 24, 2024
21d78a4
refactor files
dbrajovic Jan 24, 2024
6c330c1
refactor interface usage
dbrajovic Jan 24, 2024
62077b0
remove file
dbrajovic Jan 24, 2024
e237f16
tidy
dbrajovic Jan 24, 2024
ce646ce
Merge branch 'cosmos-pkg' into refactor-and-log
dbrajovic Jan 24, 2024
262466f
introduce common ctor for cosmos network
dbrajovic Jan 24, 2024
48fda1a
simplify cosmos pkg api
dbrajovic Jan 24, 2024
91a5878
refactor
dbrajovic Jan 24, 2024
8fcdf78
refactor 2
dbrajovic Jan 24, 2024
2e74f9f
cleanup
dbrajovic Jan 25, 2024
e478c71
cleanup 2
dbrajovic Jan 25, 2024
eb28487
cleanup 3
dbrajovic Jan 25, 2024
7eea731
refactor SendEthereumClaims
dbrajovic Jan 25, 2024
282871a
refactor cosmos keyring
dbrajovic Jan 25, 2024
aba8b11
fix init
dbrajovic Jan 25, 2024
f8462e7
fix keyring init
dbrajovic Jan 25, 2024
dd8648d
refactor cosmos keyring usage
dbrajovic Jan 25, 2024
20bfe63
cleanup
dbrajovic Jan 26, 2024
aeced1a
refactor configs
dbrajovic Jan 26, 2024
075d2e0
clean orchestrator cmd
dbrajovic Jan 26, 2024
a69eb36
refactor orch apis
dbrajovic Jan 27, 2024
11bfc5e
fix keyring init
dbrajovic Jan 27, 2024
10f2cb1
simplify loop construction
dbrajovic Jan 27, 2024
922f1f6
extract retry func
dbrajovic Jan 27, 2024
5406bf5
remove unused field
dbrajovic Jan 29, 2024
fedc82d
move ethereum network interface
dbrajovic Jan 29, 2024
8ee9d71
refactor ethereum network config
dbrajovic Jan 29, 2024
84b7da1
chore: format
albertchon Feb 21, 2024
1d35acd
fix: comment
albertchon Feb 21, 2024
395e783
skip batches that timed out when relaying
dbrajovic Mar 13, 2024
740b2a7
start relayer mode when validator is unbonded
dbrajovic Mar 14, 2024
4beb1cd
Merge branch 'refactor-and-log' of https://github.com/InjectiveLabs/p…
dbrajovic Mar 14, 2024
70c0e10
Merge branch 'fix/timed-out-batches' into refactor-and-log
dbrajovic Mar 15, 2024
dead994
display token decimals
dbrajovic Mar 15, 2024
be6f94f
debug
dbrajovic Mar 15, 2024
2845da7
debug
dbrajovic Mar 15, 2024
054d945
parse decimals result
dbrajovic Mar 15, 2024
4d6c217
support non-standard decimal tokens for batching
dbrajovic Mar 15, 2024
c70fae7
logs in oracle
dbrajovic Mar 18, 2024
69cc74c
refactor
dbrajovic Mar 20, 2024
26b04a0
remove audit fixes for a future PR
dbrajovic Mar 22, 2024
88d0a5f
reduce resync interval and inform user if an event claim was missed
dbrajovic Mar 22, 2024
0ed8394
return oracle loop early if validator is not in active set
dbrajovic Mar 22, 2024
2815c99
start peggo in relayer mode only if there is no previously registered…
dbrajovic Mar 22, 2024
db2d0a4
fix log
dbrajovic Mar 22, 2024
d0a7e9f
fix log and increase resyncInterval to 1 day
dbrajovic Mar 25, 2024
54c2fe4
fix log
dbrajovic Mar 25, 2024
890fc98
cleanup oracle
dbrajovic Mar 25, 2024
4a7aabe
add todo
dbrajovic Mar 25, 2024
1511603
rename file
dbrajovic Mar 25, 2024
34b2d74
simplify logs
dbrajovic Mar 25, 2024
b4f8a17
log
dbrajovic Mar 25, 2024
3c9ef19
fix logs
dbrajovic Mar 25, 2024
52c739a
simplify signer code
dbrajovic Mar 25, 2024
98f3e80
simplify relayer
dbrajovic Mar 25, 2024
4ce6859
rename file
dbrajovic Mar 26, 2024
e6cd0a0
replace old file
dbrajovic Mar 26, 2024
6d08b40
remove file
dbrajovic Mar 26, 2024
889a7ce
new file
dbrajovic Mar 26, 2024
ce69bba
use token decimals when calculating batch fees
dbrajovic Mar 26, 2024
200aef0
skip timed out batches when relaying
dbrajovic Mar 26, 2024
965645c
init logs
dbrajovic Mar 28, 2024
b38ec43
Merge branch 'refactor-and-log' into fix/audit
dbrajovic Mar 28, 2024
0cdf0c8
dont retry on a failed batch submission
dbrajovic Mar 28, 2024
6381f2a
Merge branch 'refactor-and-log' into fix/audit
dbrajovic Mar 28, 2024
a144a72
log
dbrajovic Mar 28, 2024
ce998dd
Merge branch 'refactor-and-log' into fix/audit
dbrajovic Mar 28, 2024
83b41ef
remove more logs
dbrajovic Mar 28, 2024
50e3890
Merge branch 'refactor-and-log' into fix/audit
dbrajovic Mar 28, 2024
160b714
fix/github actions tags
nmarcetic Mar 28, 2024
2d84e97
refactor unit tests
dbrajovic Mar 28, 2024
14c28ab
Merge branch 'refactor-and-log' into fix/audit
dbrajovic Mar 29, 2024
1cf5dc3
Merge branch 'fix/audit' of https://github.com/InjectiveLabs/peggo in…
dbrajovic Mar 29, 2024
e83a49d
Merge pull request #115 from InjectiveLabs/fix/audit
dbrajovic May 13, 2024
3609994
fix non existent token
dbrajovic May 14, 2024
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
10 changes: 1 addition & 9 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,7 @@ jobs:
- name: Build image and push
run: |
cd peggo/
TAG=$(echo ${GITHUB_REF#refs/heads/} | cut -d '/' -f 2)
TAG=${{ github.ref_name }}
echo $TAG
[[ $ECR_ENABLED == "false" ]] || docker buildx build --tag $ECR_REPO:$TAG --platform linux/amd64,linux/arm64 --push .
[[ $GHCR_ENABLED == "false" ]] || docker buildx build --tag $GHCR_REPO:$TAG --platform linux/amd64,linux/arm64 --push .

- name: NONROOT Build image and push
run: |
cd peggo/
TAG=$(echo ${GITHUB_REF#refs/heads/} | cut -d '/' -f 2)-nonroot
echo $TAG
[[ $ECR_ENABLED == "false" ]] || docker buildx build -f Dockerfile.nonroot --tag $ECR_REPO:$TAG --platform linux/amd64,linux/arm64 --push .
[[ $GHCR_ENABLED == "false" ]] || docker buildx build -f Dockerfile.nonroot --tag $GHCR_REPO:$TAG --platform linux/amd64,linux/arm64 --push .
181 changes: 0 additions & 181 deletions cmd/peggo/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@ package main

import (
"bytes"
"crypto/rand"
"fmt"
"io"
"log"
"math/big"
"os"
"path/filepath"
"strings"
"syscall"

cosmcrypto "github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
cosmtypes "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/usbwallet"
Expand All @@ -27,154 +20,9 @@ import (
"github.com/pkg/errors"
"golang.org/x/crypto/ssh/terminal"

"github.com/InjectiveLabs/sdk-go/chain/crypto/ethsecp256k1"
"github.com/InjectiveLabs/sdk-go/chain/crypto/hd"

"github.com/InjectiveLabs/peggo/orchestrator/ethereum/keystore"
)

const defaultKeyringKeyName = "validator"

var emptyCosmosAddress = cosmtypes.AccAddress{}
var cdc = MakeEncodingConfig().Marshaler

func initCosmosKeyring(
cosmosKeyringDir *string,
cosmosKeyringAppName *string,
cosmosKeyringBackend *string,
cosmosKeyFrom *string,
cosmosKeyPassphrase *string,
cosmosPrivKey *string,
cosmosUseLedger *bool,
) (cosmtypes.AccAddress, keyring.Keyring, error) {

switch {
case len(*cosmosPrivKey) > 0:
if *cosmosUseLedger {
err := errors.New("cannot combine ledger and privkey options")
return emptyCosmosAddress, nil, err
}

pkBytes, err := hexToBytes(*cosmosPrivKey)
if err != nil {
err = errors.Wrap(err, "failed to hex-decode cosmos account privkey")
return emptyCosmosAddress, nil, err
}

// Specfic to Injective chain with Ethermint keys
// Should be secp256k1.PrivKey for generic Cosmos chain
cosmosAccPk := &ethsecp256k1.PrivKey{
Key: pkBytes,
}

addressFromPk := cosmtypes.AccAddress(cosmosAccPk.PubKey().Address().Bytes())

var keyName string

// check that if cosmos 'From' specified separately, it must match the provided privkey,
if len(*cosmosKeyFrom) > 0 {
addressFrom, err := cosmtypes.AccAddressFromBech32(*cosmosKeyFrom)
if err == nil {
if !bytes.Equal(addressFrom.Bytes(), addressFromPk.Bytes()) {
err = errors.Errorf("expected account address %s but got %s from the private key", addressFrom.String(), addressFromPk.String())
return emptyCosmosAddress, nil, err
}
} else {
// use it as a name then
keyName = *cosmosKeyFrom
}
}

if len(keyName) == 0 {
keyName = defaultKeyringKeyName
}

// wrap a PK into a Keyring
kb, err := KeyringForPrivKey(keyName, cosmosAccPk)
return addressFromPk, kb, err

case len(*cosmosKeyFrom) > 0:
var fromIsAddress bool
addressFrom, err := cosmtypes.AccAddressFromBech32(*cosmosKeyFrom)
if err == nil {
fromIsAddress = true
}

var passReader io.Reader = os.Stdin
if len(*cosmosKeyPassphrase) > 0 {
passReader = newPassReader(*cosmosKeyPassphrase)
}

var absoluteKeyringDir string
if filepath.IsAbs(*cosmosKeyringDir) {
absoluteKeyringDir = *cosmosKeyringDir
} else {
absoluteKeyringDir, _ = filepath.Abs(*cosmosKeyringDir)
}

kb, err := keyring.New(
*cosmosKeyringAppName,
*cosmosKeyringBackend,
absoluteKeyringDir,
passReader,
cdc,
hd.EthSecp256k1Option(),
)
if err != nil {
err = errors.Wrap(err, "failed to init keyring")
return emptyCosmosAddress, nil, err
}

var keyInfo *keyring.Record
if fromIsAddress {
if keyInfo, err = kb.KeyByAddress(addressFrom); err != nil {
err = errors.Wrapf(err, "couldn't find an entry for the key %s in keybase", addressFrom.String())
return emptyCosmosAddress, nil, err
}
} else {
if keyInfo, err = kb.Key(*cosmosKeyFrom); err != nil {
err = errors.Wrapf(err, "could not find an entry for the key '%s' in keybase", *cosmosKeyFrom)
return emptyCosmosAddress, nil, err
}
}

switch keyType := keyInfo.GetType(); keyType {
case keyring.TypeLocal:
// kb has a key and it's totally usable
addr, err := keyInfo.GetAddress()
if err != nil {
return emptyCosmosAddress, nil, err
}
return addr, kb, nil
case keyring.TypeLedger:
// the kb stores references to ledger keys, so we must explicitly
// check that. kb doesn't know how to scan HD keys - they must be added manually before
if *cosmosUseLedger {
addr, err := keyInfo.GetAddress()
if err != nil {
return emptyCosmosAddress, nil, err
}
return addr, kb, nil
}
err := errors.Errorf("'%s' key is a ledger reference, enable ledger option", keyInfo.Name)
return emptyCosmosAddress, nil, err
case keyring.TypeOffline:
err := errors.Errorf("'%s' key is an offline key, not supported yet", keyInfo.Name)
return emptyCosmosAddress, nil, err
case keyring.TypeMulti:
err := errors.Errorf("'%s' key is an multisig key, not supported yet", keyInfo.Name)
return emptyCosmosAddress, nil, err
default:
err := errors.Errorf("'%s' key has unsupported type: %s", keyInfo.Name, keyType)
return emptyCosmosAddress, nil, err
}

default:
err := errors.New("insufficient cosmos key details provided")
return emptyCosmosAddress, nil, err
}
}

var emptyEthAddress = ethcmn.Address{}

func initEthereumAccountsManager(
Expand Down Expand Up @@ -392,32 +240,3 @@ func (r *passReader) Read(p []byte) (n int, err error) {

return
}

// KeyringForPrivKey creates a temporary in-mem keyring for a PrivKey.
// Allows to init Context when the key has been provided in plaintext and parsed.
func KeyringForPrivKey(name string, privKey cryptotypes.PrivKey) (keyring.Keyring, error) {
kb := keyring.NewInMemory(cdc, hd.EthSecp256k1Option())
tmpPhrase := randPhrase(64)
armored := cosmcrypto.EncryptArmorPrivKey(privKey, tmpPhrase, privKey.Type())
err := kb.ImportPrivKey(name, armored, tmpPhrase)
if err != nil {
err = errors.Wrap(err, "failed to import privkey")
return nil, err
}

return kb, nil
}

func randPhrase(size int) string {
buf := make([]byte, size)
_, err := rand.Read(buf)
orPanic(err)

return string(buf)
}

func orPanic(err error) {
if err != nil {
log.Panicln()
}
}
Loading