Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Initial implementation of app-specific actions #580

Merged
merged 40 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fd7f82d
Add actions to the config file
lukasz-zimnoch Oct 14, 2020
624400b
Add TBTC actions and chain extensions stub
lukasz-zimnoch Oct 14, 2020
376dc70
Return struct from the connect function
lukasz-zimnoch Oct 14, 2020
52b3e48
Enable app-specific actions in the start command
lukasz-zimnoch Oct 14, 2020
3f318a3
Use TBTC contract bindings
lukasz-zimnoch Oct 14, 2020
ce789c2
Bump up tbtc go bindings
lukasz-zimnoch Oct 14, 2020
a48c965
Align with tbtc bindings changes
lukasz-zimnoch Oct 15, 2020
3890ebf
Actions structure change
lukasz-zimnoch Oct 15, 2020
c378e7e
Merge branch 'master' into app-specific-actions
lukasz-zimnoch Oct 15, 2020
40f2f9c
Use TBTCSystem contract binding and config rework
lukasz-zimnoch Oct 15, 2020
a438ec0
Rework the ethereum extensions structure
lukasz-zimnoch Oct 15, 2020
31e98b6
Merge branch 'master' into app-specific-actions
lukasz-zimnoch Oct 15, 2020
2d3019a
Implementation of the `retrievePubkey` action
lukasz-zimnoch Oct 16, 2020
e97914a
Add GoSec exception for random jitter generator
lukasz-zimnoch Oct 16, 2020
d6d2a26
Simplify extension section in the config sample
lukasz-zimnoch Oct 19, 2020
a64dbc2
Use extension-centric naming
lukasz-zimnoch Oct 19, 2020
f6dd208
Move `TBTCEthereumChain` to the `ethereum` package
lukasz-zimnoch Oct 19, 2020
6025d32
Merge branch 'master' into app-specific-actions
lukasz-zimnoch Oct 19, 2020
81118a8
Update tbtc bindings dependency
lukasz-zimnoch Oct 19, 2020
4a88afb
Use extension-centric naming - next part
lukasz-zimnoch Oct 19, 2020
e475ff7
Extract TBTC chain interfaces to separate file
lukasz-zimnoch Oct 19, 2020
0834f76
Extract `maxTransactionAttempts` constant
lukasz-zimnoch Oct 19, 2020
3523e60
Align some naming in the tbtc extensions code
lukasz-zimnoch Oct 19, 2020
a7c3cd0
Basic unit tests for app-specific extensions
lukasz-zimnoch Oct 19, 2020
302323f
Extended unit tests for app-specific extensions
lukasz-zimnoch Oct 20, 2020
caeb475
Add new GoSec exceptions
lukasz-zimnoch Oct 20, 2020
71851ad
Change the comment describing `Extensions.TBTC`
lukasz-zimnoch Oct 20, 2020
2f046a2
Change `pkg/chain` alias in tbtc extensions code
lukasz-zimnoch Oct 20, 2020
7899037
Improve general naming and logs
lukasz-zimnoch Oct 20, 2020
6c88853
Satisfy the GoSec checker
lukasz-zimnoch Oct 20, 2020
4a8b996
Update tbtc bindings
lukasz-zimnoch Oct 20, 2020
57fa352
Merge branch 'master' into app-specific-actions
lukasz-zimnoch Oct 23, 2020
8cac02d
Add additional explanation to `[Extensions.TBTC]`
lukasz-zimnoch Oct 23, 2020
bb6f6f0
Tidy the go.sum
lukasz-zimnoch Oct 23, 2020
b51ce89
Improve docs for `TBTC` config struct
lukasz-zimnoch Oct 23, 2020
89f436b
Minor naming improvements of tbtc extensions
lukasz-zimnoch Oct 23, 2020
71efdea
Minor naming improvements of local chain and tests
lukasz-zimnoch Oct 23, 2020
3b6082d
Add a panic in case of `createKeepWithMembers` err
lukasz-zimnoch Oct 23, 2020
0be18c6
Remove the `nosec` from local `OpenKeep`
lukasz-zimnoch Oct 23, 2020
becf9e3
Change timeout message for tbtc extension
lukasz-zimnoch Oct 23, 2020
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
23 changes: 22 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package cmd
import (
"context"
"fmt"
"github.com/keep-network/keep-core/pkg/diagnostics"
"time"

"github.com/keep-network/keep-core/pkg/diagnostics"
"github.com/keep-network/keep-ecdsa/pkg/actions"

"github.com/keep-network/keep-core/pkg/chain"
"github.com/keep-network/keep-core/pkg/metrics"
"github.com/keep-network/keep-core/pkg/net"
Expand Down Expand Up @@ -168,6 +170,8 @@ func Start(c *cli.Context) error {
)
logger.Debugf("initialized operator with address: [%s]", ethereumKey.Address.String())

initializeApplicationSpecificActions(config.Actions, ethereumChain)

initializeMetrics(ctx, config, networkProvider, stakeMonitor, ethereumKey.Address.Hex())
initializeDiagnostics(config, networkProvider)

Expand All @@ -183,6 +187,23 @@ func Start(c *cli.Context) error {
}
}

func initializeApplicationSpecificActions(
pdyraga marked this conversation as resolved.
Show resolved Hide resolved
actionsConfig config.Actions,
ethereumChain *ethereum.EthereumChain,
) {
if len(actionsConfig.TBTC.DepositLog) > 0 {
tbtcEthereumChain, err := ethereum.WithTBTCExtensions(
ethereumChain,
actionsConfig.TBTC.DepositLog,
)
if err != nil {

}

actions.InitializeTBTCActions(tbtcEthereumChain)
}
}

func initializeMetrics(
ctx context.Context,
config *config.Config,
Expand Down
7 changes: 6 additions & 1 deletion configs/config.toml.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,9 @@
# The port on which the `/diagnostics` endpoint will be available can be
# customized below.
# [Diagnostics]
# Port = 8081
# Port = 8081

[Actions]
pdyraga marked this conversation as resolved.
Show resolved Hide resolved
[TBTC]
DepositLog = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/ipfs/go-log v1.0.4
github.com/keep-network/keep-common v1.2.1-0.20201002105641-e04cc579ff66
github.com/keep-network/keep-core v1.3.0
github.com/keep-network/tbtc/bindings/go v0.0.0-20201014164341-29eeaf8dfc0f
github.com/pkg/errors v0.9.1
github.com/urfave/cli v1.22.1
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ github.com/keep-network/keep-common v1.2.1-0.20201002105641-e04cc579ff66 h1:x/9f
github.com/keep-network/keep-common v1.2.1-0.20201002105641-e04cc579ff66/go.mod h1:emxogTbBdey7M3jOzfxZOdfn139kN2mI2b2wA6AHKKo=
github.com/keep-network/keep-core v1.3.0 h1:7Tb33EmO/ntHOEbOiYciRlBhqu5Ln6KemWCaYK0Z6LA=
github.com/keep-network/keep-core v1.3.0/go.mod h1:1KsSSTQoN754TrFLW7kLy50pOG2CQ4BOfnJqdvEG7FA=
github.com/keep-network/tbtc v1.1.0 h1:9ZCuBsrJYN1L1V7bAC98ZAtxv+ZIHcMhz6RJLAizLvY=
github.com/keep-network/tbtc v1.1.1-0.20201014164341-29eeaf8dfc0f h1:d5kn2pPyT/XWKepB9/g1fRTF+AN1EnPXZcX1Q8hJjpw=
github.com/keep-network/tbtc/bindings/go v0.0.0-20201014164341-29eeaf8dfc0f h1:DxZXCteXGQGR8B/45AWJU2Xvpei4diP+xc3R0kYVTkQ=
github.com/keep-network/tbtc/bindings/go v0.0.0-20201014164341-29eeaf8dfc0f/go.mod h1:uEeNDO/K1AjOPE19rRo39sa76tZgTCYSOdJNSJrLG1o=
github.com/keep-network/toml v0.3.0 h1:G+NJwWR/ZiORqeLBsDXDchYoL29PXHdxOPcCueA7ctE=
github.com/keep-network/toml v0.3.0/go.mod h1:Zeyd3lxbIlMYLREho3UK1dMP2xjqt2gLkQ5E5vM6K38=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand Down
11 changes: 11 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Config struct {
TSS tss.Config
Metrics Metrics
Diagnostics Diagnostics
Actions Actions
}

// SanctionedApplications contains addresses of applications approved by the
Expand Down Expand Up @@ -70,6 +71,16 @@ type Diagnostics struct {
Port int
}

// Actions stores app-specific actions configuration.
type Actions struct {
TBTC TBTCActions
}

// TBTCActions stores configuration related with TBTC-specific actions.
type TBTCActions struct {
DepositLog string
}

// ReadConfig reads in the configuration file in .toml format. Ethereum key file
// password is expected to be provided as environment variable.
func ReadConfig(filePath string) (*Config, error) {
Expand Down
49 changes: 49 additions & 0 deletions pkg/actions/tbtc_actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package actions
pdyraga marked this conversation as resolved.
Show resolved Hide resolved

import (
"math/big"

"github.com/ipfs/go-log"
"github.com/keep-network/keep-common/pkg/subscription"
eth "github.com/keep-network/keep-ecdsa/pkg/chain"
)

var logger = log.Logger("keep-actions")

// TBTCHandle represents a chain handle extended with TBTC-specific capabilities.
type TBTCHandle interface {
eth.Handle

Deposit
DepositLog
}

// Deposit is an interface that provides ability to interact
// with Deposit contracts.
type Deposit interface {
}

// DepositLog is an interface that provides ability to interact
// with DepositLog contract.
type DepositLog interface {
// OnDepositCreated installs a callback that is invoked when an
// on-chain notification of a new deposit creation is seen.
OnDepositCreated(
handler func(depositAddress, keepAddress string, timestamp *big.Int),
) subscription.EventSubscription
}

// InitializeTBTCActions initializes actions specific for the TBTC application.
func InitializeTBTCActions(tbtcHandle TBTCHandle) {
logger.Infof("initializing tbtc-specific actions")

tbtcHandle.OnDepositCreated(func(
depositAddress,
keepAddress string,
timestamp *big.Int,
) {
// TODO: Implementation
})

logger.Infof("tbtc-specific actions have been initialized")
}
3 changes: 1 addition & 2 deletions pkg/chain/ethereum/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/keep-network/keep-common/pkg/chain/ethereum"
"github.com/keep-network/keep-common/pkg/chain/ethereum/blockcounter"
"github.com/keep-network/keep-common/pkg/chain/ethereum/ethutil"
eth "github.com/keep-network/keep-ecdsa/pkg/chain"
"github.com/keep-network/keep-ecdsa/pkg/chain/gen/contract"
)

Expand Down Expand Up @@ -60,7 +59,7 @@ type EthereumChain struct {

// Connect performs initialization for communication with Ethereum blockchain
// based on provided config.
func Connect(accountKey *keystore.Key, config *ethereum.Config) (eth.Handle, error) {
func Connect(accountKey *keystore.Key, config *ethereum.Config) (*EthereumChain, error) {
pdyraga marked this conversation as resolved.
Show resolved Hide resolved
client, err := ethclient.Dial(config.URL)
if err != nil {
return nil, err
Expand Down
73 changes: 73 additions & 0 deletions pkg/chain/ethereum/tbtc_extensions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package ethereum

import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/keep-network/keep-common/pkg/subscription"
"github.com/keep-network/tbtc/bindings/go/contract"
)

// TBTCEthereumChain represents an Ethereum chain handle with
// TBTC-specific capabilities.
type TBTCEthereumChain struct {
pdyraga marked this conversation as resolved.
Show resolved Hide resolved
*EthereumChain

depositLogContract *contract.DepositLog
}

// WithTBTCExtensions extends the Ethereum chain handle with
// TBTC-specific capabilities.
func WithTBTCExtensions(
ethereumChain *EthereumChain,
depositLogContractAddress string,
) (*TBTCEthereumChain, error) {
if !common.IsHexAddress(depositLogContractAddress) {
return nil, fmt.Errorf("incorrect deposit log contract address")
}

depositLogContract, err := contract.NewDepositLog(
common.HexToAddress(depositLogContractAddress),
ethereumChain.accountKey,
ethereumChain.client,
ethereumChain.nonceManager,
ethereumChain.miningWaiter,
ethereumChain.transactionMutex,
)
if err != nil {
return nil, err
}

return &TBTCEthereumChain{
EthereumChain: ethereumChain,
depositLogContract: depositLogContract,
}, nil
}

// OnDepositCreated installs a callback that is invoked when an
// on-chain notification of a new deposit creation is seen.
func (tec *TBTCEthereumChain) OnDepositCreated(
handler func(depositAddress, keepAddress string, timestamp *big.Int),
) subscription.EventSubscription {
subscription, err := tec.depositLogContract.WatchCreated(
func(
DepositContractAddress common.Address,
KeepAddress common.Address,
Timestamp *big.Int,
blockNumber uint64,
) {
handler(DepositContractAddress.Hex(), KeepAddress.Hex(), Timestamp)
},
func(err error) error {
return fmt.Errorf("watch deposit created failed: [%v]", err)
},
nil,
nil,
)
if err != nil {
logger.Errorf("could not watch Created event: [%v]", err)
}

return subscription
}