Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ tmp/

# Output directory
out/
storage/
logs/
data/
18 changes: 18 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmd
import (
"context"
"fmt"
"time"

"github.com/keep-network/keep-core/pkg/tbtcpg"

"github.com/keep-network/keep-common/pkg/persistence"
Expand Down Expand Up @@ -87,6 +89,22 @@ func start(cmd *cobra.Command) error {
blockCounter,
)

// Wire performance metrics into network provider if available
if clientInfoRegistry != nil {
perfMetrics := clientinfo.NewPerformanceMetrics(clientInfoRegistry)
// Type assert to libp2p provider to set metrics recorder
// The provider struct is not exported, so we use interface assertion
if setter, ok := netProvider.(interface {
SetMetricsRecorder(recorder interface {
IncrementCounter(name string, value float64)
SetGauge(name string, value float64)
RecordDuration(name string, duration time.Duration)
})
}); ok {
setter.SetMetricsRecorder(perfMetrics)
}
}

// Initialize beacon and tbtc only for non-bootstrap nodes.
// Skip initialization for bootstrap nodes as they are only used for network
// discovery.
Expand Down
132 changes: 132 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# This is a sample TOML configuration file for the Keep client.

[ethereum]
URL = "ws://127.0.0.1:8546"
KeyFile = "/Users/levakhnazarov/ethereum/data/keystore/UTC--2025-12-18T18-53-35.539381000Z--7966c178f466b060aaeb2b91e9149a5fb2ec9c53"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This contains a hardcoded local path and timestamp. Consider using a placeholder like <YOUR_KEYFILE_PATH> or moving this to configs/config.toml.SAMPLE instead of committing it to the repo root.

KeyFilePassword = "password"

# Uncomment to override the defaults for transaction status monitoring.

# MiningCheckInterval is the interval in which transaction
# mining status is checked. If the transaction is not mined within this
# time, the gas price is increased and transaction is resubmitted.
#
# MiningCheckInterval = 60 # 60 sec (default value)

# MaxGasFeeCap specifies the maximum gas fee cap the client is
# willing to pay for the transaction to be mined. The offered transaction
# gas cost can not be higher than the max gas fee cap value. If the maximum
# allowed gas fee cap is reached, no further resubmission attempts are
# performed. This property should be set only for Ethereum. In case of
# legacy non-EIP-1559 transactions, this field works in the same way as
# `MaxGasPrice` property.
#
# MaxGasFeeCap = "500 Gwei" # 500 Gwei (default value)

# Uncomment to enable Ethereum node rate limiting. Both properties can be
# used together or separately.
#
# RequestsPerSecondLimit sets the maximum average number of requests
# per second which can be executed against the Ethereum node.
# All types of Ethereum node requests are rate-limited,
# including view function calls.
#
# RequestsPerSecondLimit = 150

# ConcurrencyLimit sets the maximum number of concurrent requests which
# can be executed against the Ethereum node at the same time.
# This limit affects all types of Ethereum node requests,
# including view function calls.
#
# ConcurrencyLimit = 30

# BalanceAlertThreshold defines a minimum value of the operator's account
# balance below which the client will start reporting errors in logs.
# A value can be provided in `wei`, `Gwei` or `ether`, e.g. `7.5 ether`,
# `7500000000 Gwei`.
#
# BalanceAlertThreshold = "0.5 ether" # 0.5 ether (default value)

[bitcoin.electrum]
# URL to the Electrum server in format: `scheme://hostname:port`.
# Should be uncommented only when using a custom Electrum server. Otherwise,
# one of the default embedded servers is selected randomly at startup.
# For local development, a URL is required to pass validation.
# Using a testnet Electrum server URL as a placeholder.
# Replace this with a real Electrum server URL if needed for Bitcoin functionality.
URL = "tcp://148.251.237.196:50001"

# Timeout for a single attempt of Electrum connection establishment.
# ConnectTimeout = "10s"

# Timeout for Electrum connection establishment retries.
# ConnectRetryTimeout = "1m"

# Timeout for a single attempt of Electrum protocol request.
# RequestTimeout = "30s"

# Timeout for Electrum protocol request retries.
# RequestRetryTimeout = "2m"

# Interval for connection keep alive requests.
# KeepAliveInterval = "5m"

[network]
Bootstrap = false
Peers = [
"/ip4/127.0.0.1/tcp/3919/ipfs/16Uiu2HAmFRJtCWfdXhZEZHWb4tUpH1QMMgzH1oiamCfUuK6NgqWX",
]
Port = 3920

# Uncomment to override the node's default addresses announced in the network
# AnnouncedAddresses = ["/dns4/example.com/tcp/3919", "/ip4/80.70.60.50/tcp/3919"]

# Uncomment to enable courtesy message dissemination for topics this node is
# not subscribed to. Messages will be forwarded to peers for the duration
# specified as a value in seconds.
# Message dissemination is disabled by default and should be enabled only
# on selected bootstrap nodes. It is not a good idea to enable dissemination
# on non-bootstrap node as it may clutter communication and eventually lead
# to blacklisting the node. The maximum allowed value is 90 seconds.
#
# DisseminationTime = 90

[storage]
Dir = "/Users/levakhnazarov/threshold/fork2/keep-core/data"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, hardcoded absolute path. Might want to use a relative path or environment variable placeholder.


# ClientInfo exposes metrics and diagnostics modules.
#
# Metrics collects and exposes information useful for external monitoring tools usually
# operating on time series data.
# All values exposed by metrics module are quantifiable or countable.
#
# The following metrics are available:
# - connected peers count
# - connected bootstraps count
# - eth client connectivity status
#
# Diagnostics module exposes the following information:
# - list of connected peers along with their network id and ethereum operator address
# - information about the client's network id and ethereum operator address
[clientInfo]
Port = 9601
NetworkMetricsTick = 60
EthereumMetricsTick = 600

# Uncomment to overwrite default values for TBTC config.
#
# [tbtc]
# PreParamsPoolSize = 3000
# PreParamsGenerationTimeout = "2m"
# PreParamsGenerationDelay = "10s"
# PreParamsGenerationConcurrency = 1
# KeyGenerationConcurrency = 1

# Developer options to work with locally deployed contracts
[developer]
TokenStakingAddress = "0xAAA02A6D82732e0c08D2C7A75594CcDb064a9E03"
RandomBeaconAddress = "0x3b64D7b2C08a23307163cd1658e7d8e9935882D2"
WalletRegistryAddress = "0xd49141e044801DEE237993deDf9684D59fafE2e6"
BridgeAddress = "0xc0a2ee534F004a4ec2EFA541489acBD5ff4bBA99"
MaintainerProxyAddress = "0x6d19C0b4bd2B49eCa000C2Fd910c2Db9607f34ee"
WalletProposalValidatorAddress = "0x5f7dC10e6dD504EEB41678E287aa1732F5EA85c4"
72 changes: 72 additions & 0 deletions deposit-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Deposit Data for Testing

This directory contains deposit data structures prepared for tBTC testing.

## Files

- **deposit-data.json** - Complete deposit information including all parameters
- **funding-tx-info.json** - BitcoinTxInfo structure for `revealDeposit()` call
- **deposit-reveal-info.json** - DepositDepositRevealInfo structure for `revealDeposit()` call

## Usage

### Regenerate Deposit Data

```bash
./scripts/emulate-deposit.sh [depositor_address] [amount_satoshis]
```

Examples:
```bash
# Use default values (random depositor, 1 BTC)
./scripts/emulate-deposit.sh

# Specify depositor address
./scripts/emulate-deposit.sh 0x1234...abcd

# Specify depositor and amount (0.5 BTC = 50000000 satoshis)
./scripts/emulate-deposit.sh 0x1234...abcd 50000000
```

### Using the Data

The generated JSON files can be used with:

1. **keep-client** (if Bridge supports revealDeposit):
```bash
keep-client bridge reveal-deposit \
--funding-tx-info "$(cat funding-tx-info.json | jq -c .)" \
--deposit-reveal-info "$(cat deposit-reveal-info.json | jq -c .)"
```

2. **cast** (if Bridge contract has revealDeposit function):
```bash
cast send <BRIDGE_ADDRESS> \
"revealDeposit((bytes4,bytes,bytes,bytes4),(uint32,bytes8,bytes20,bytes20,bytes4,address))" \
"$(cat funding-tx-info.json | jq -c .)" \
"$(cat deposit-reveal-info.json | jq -c .)" \
--rpc-url http://localhost:8545
```

## Data Structure Details

### BitcoinTxInfo
- `version`: Bitcoin transaction version (4 bytes)
- `inputVector`: Serialized transaction inputs
- `outputVector`: Serialized transaction outputs
- `locktime`: Transaction locktime (4 bytes)

### DepositDepositRevealInfo
- `fundingOutputIndex`: Index of the output in funding transaction
- `blindingFactor`: 8-byte random value to distinguish deposits
- `walletPubKeyHash`: 20-byte hash of wallet public key (RIPEMD160(SHA256(compressed_pubkey)))
- `refundPubKeyHash`: 20-byte hash of refund public key
- `refundLocktime`: 4-byte refund locktime
- `vault`: Optional vault address (zero if not used)

## Notes

- The wallet public key hash is calculated from the actual wallet created via DKG
- Funding transaction data is mocked for testing purposes
- In production, these would come from actual Bitcoin transactions
- BridgeStub doesn't implement `revealDeposit()` - deploy full Bridge contract for testing
26 changes: 26 additions & 0 deletions deposit-data/deposit-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"depositor": "0xf0ec7364a8281ca906a4cf3526feb0989cf843a9",
"amount": 100000000,
"amountBTC": 1.00000000,
"fundingTxHash": "0x5764558a1065e0ca95732a81d5d64f3568b8607da06419c0706fdacf62db2bca",
"fundingOutputIndex": 0,
"walletID": "0x2fc6a693193fef87e90c6ccc9cfdbc12607422f45407c0416340ddd6ed470b9e",
"walletPublicKeyHash": "0x31e67e42a93bbe7f6e5c932232d38e42061369b7",
"blindingFactor": "0xa47d3d2c8a1d53f8",
"refundPublicKeyHash": "0x8223501baee1fbf3f9bbc8256258edeb66e5b94f",
"refundLocktime": "0x695457d0",
"fundingTxInfo": {
"version": "0x01000000",
"inputVector": "0x019b0b5f5c124c4c04d79de61309c34a607fa3b3867a9dbd82f30bfb54cdbec7a7be12fe5c25ddf3e9ba4eeca4f16fe46768604165e2d6381b7555d7782d4cd443ffffffff",
"outputVector": "0x010017f0ec7364a8281ca906a4cf3526feb0989cf843a9",
"locktime": "0x00000000"
},
"depositRevealInfo": {
"fundingOutputIndex": 0,
"blindingFactor": "0xa47d3d2c8a1d53f8",
"walletPubKeyHash": "0x31e67e42a93bbe7f6e5c932232d38e42061369b7",
"refundPubKeyHash": "0x8223501baee1fbf3f9bbc8256258edeb66e5b94f",
"refundLocktime": "0x695457d0",
"vault": "0x0000000000000000000000000000000000000000"
}
}
8 changes: 8 additions & 0 deletions deposit-data/deposit-reveal-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"fundingOutputIndex": 0,
"blindingFactor": "0xa47d3d2c8a1d53f8",
"walletPubKeyHash": "0x31e67e42a93bbe7f6e5c932232d38e42061369b7",
"refundPubKeyHash": "0x8223501baee1fbf3f9bbc8256258edeb66e5b94f",
"refundLocktime": "0x695457d0",
"vault": "0x0000000000000000000000000000000000000000"
}
6 changes: 6 additions & 0 deletions deposit-data/funding-tx-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "0x01000000",
"inputVector": "0x019b0b5f5c124c4c04d79de61309c34a607fa3b3867a9dbd82f30bfb54cdbec7a7be12fe5c25ddf3e9ba4eeca4f16fe46768604165e2d6381b7555d7782d4cd443ffffffff",
"outputVector": "0x010017f0ec7364a8281ca906a4cf3526feb0989cf843a9",
"locktime": "0x00000000"
}
11 changes: 9 additions & 2 deletions docs-v1/development/local-keep-network.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ addresses. The account under alloc is the address of the account prepended with
"petersburgBlock": 0,
"daoForkBlock": 0,
"istanbulBlock": 0,
"daoForkSupport": true
"daoForkSupport": true,
"terminalTotalDifficulty": null
},
"difficulty": "0x20",
"gasLimit": "0x7A1200",
Expand Down Expand Up @@ -163,9 +164,15 @@ $ geth --port 3000 --networkid 1101 --identity "somerandomidentity" \
--rpcapi "db,ssh,miner,admin,eth,net,web3,personal" \
--wsapi "db,ssh,miner,admin,eth,net,web3,personal" \
--datadir=$GETH_DATA_DIR --syncmode "fast" \
--miner.etherbase=$GETH_ETHEREUM_ACCOUNT --mine --miner.threads=1 \
--allow-insecure-unlock

NOTE: Geth 1.16+ removed PoW mining support. For private PoW networks, use Geth 1.13.x or earlier.
If using Geth 1.13.x or earlier, you can start mining with:
--mine --miner.threads=1 --miner.etherbase=$GETH_ETHEREUM_ACCOUNT
Or via console:
miner.setEtherbase(eth.accounts[0])
miner.start(1)

INFO [10-31|15:02:22.113] Maximum peer count ETH=25 LES=0 total=25
INFO [10-31|15:02:22.128] Starting peer-to-peer node instance=Geth/somerandomidentity/v1.8.14-stable/darwin-amd64/go1.10.3
INFO [10-31|15:02:22.128] Allocated cache and file handles database=/Users/piotr/ethereum/data/geth/chaindata cache=768 handles=1024
Expand Down
Loading
Loading