Skip to content

Commit

Permalink
Merge branch 'master' into add-txid-to-submit-redeem-tx-response
Browse files Browse the repository at this point in the history
  • Loading branch information
altafan committed Jan 27, 2025
2 parents 583a0c1 + 179b514 commit 4b6c851
Show file tree
Hide file tree
Showing 47 changed files with 470 additions and 468 deletions.
2 changes: 1 addition & 1 deletion api-spec/openapi/swagger/ark/v1/service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@
"pubkey": {
"type": "string"
},
"roundLifetime": {
"vtxoTreeExpiry": {
"type": "string",
"format": "int64"
},
Expand Down
2 changes: 1 addition & 1 deletion api-spec/protobuf/ark/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ service ArkService {
message GetInfoRequest {}
message GetInfoResponse {
string pubkey = 1;
int64 round_lifetime = 2;
int64 vtxo_tree_expiry = 2;
int64 unilateral_exit_delay = 3;
int64 round_interval = 4;
string network = 5;
Expand Down
542 changes: 271 additions & 271 deletions api-spec/protobuf/gen/ark/v1/service.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func config(ctx *cli.Context) error {
"wallet_type": cfgData.WalletType,
"client_tyep": cfgData.ClientType,
"network": cfgData.Network.Name,
"round_lifetime": cfgData.RoundLifetime,
"vtxo_tree_expiry": cfgData.VtxoTreeExpiry,
"unilateral_exit_delay": cfgData.UnilateralExitDelay,
"dust": cfgData.Dust,
"boarding_descriptor_template": cfgData.BoardingDescriptorTemplate,
Expand Down
12 changes: 6 additions & 6 deletions common/bitcointree/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
// CraftSharedOutput returns the taproot script and the amount of the initial root output
func CraftSharedOutput(
cosigners []*secp256k1.PublicKey, server *secp256k1.PublicKey, receivers []tree.VtxoLeaf,
feeSatsPerNode uint64, roundLifetime common.RelativeLocktime,
feeSatsPerNode uint64, vtxoTreeExpiry common.RelativeLocktime,
) ([]byte, int64, error) {
aggregatedKey, _, err := createAggregatedKeyWithSweep(
cosigners, server, roundLifetime,
cosigners, server, vtxoTreeExpiry,
)
if err != nil {
return nil, 0, err
Expand All @@ -45,10 +45,10 @@ func CraftSharedOutput(
// BuildVtxoTree creates all the tree's transactions
func BuildVtxoTree(
initialInput *wire.OutPoint, cosigners []*secp256k1.PublicKey, server *secp256k1.PublicKey, receivers []tree.VtxoLeaf,
feeSatsPerNode uint64, roundLifetime common.RelativeLocktime,
feeSatsPerNode uint64, vtxoTreeExpiry common.RelativeLocktime,
) (tree.VtxoTree, error) {
aggregatedKey, sweepTapLeaf, err := createAggregatedKeyWithSweep(
cosigners, server, roundLifetime,
cosigners, server, vtxoTreeExpiry,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -280,11 +280,11 @@ func createRootNode(
}

func createAggregatedKeyWithSweep(
cosigners []*secp256k1.PublicKey, server *secp256k1.PublicKey, roundLifetime common.RelativeLocktime,
cosigners []*secp256k1.PublicKey, server *secp256k1.PublicKey, vtxoTreeExpiry common.RelativeLocktime,
) (*musig2.AggregateKey, *psbt.TaprootTapLeafScript, error) {
sweepClosure := &tree.CSVMultisigClosure{
MultisigClosure: tree.MultisigClosure{PubKeys: []*secp256k1.PublicKey{server}},
Locktime: roundLifetime,
Locktime: vtxoTreeExpiry,
}

sweepScript, err := sweepClosure.Script()
Expand Down
8 changes: 4 additions & 4 deletions common/bitcointree/musig2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
exitDelay = 512
)

var lifetime = common.RelativeLocktime{Type: common.LocktimeTypeBlock, Value: 144}
var vtxoTreeExpiry = common.RelativeLocktime{Type: common.LocktimeTypeBlock, Value: 144}

var testTxid, _ = chainhash.NewHashFromStr("49f8664acc899be91902f8ade781b7eeb9cbe22bdd9efbc36e56195de21bcd12")

Expand All @@ -46,7 +46,7 @@ func TestRoundTripSignTree(t *testing.T) {
server.PubKey(),
castReceivers(f.Receivers),
minRelayFee,
lifetime,
vtxoTreeExpiry,
)
require.NoError(t, err)

Expand All @@ -59,13 +59,13 @@ func TestRoundTripSignTree(t *testing.T) {
server.PubKey(),
castReceivers(f.Receivers),
minRelayFee,
lifetime,
vtxoTreeExpiry,
)
require.NoError(t, err)

sweepClosure := &tree.CSVMultisigClosure{
MultisigClosure: tree.MultisigClosure{PubKeys: []*secp256k1.PublicKey{server.PubKey()}},
Locktime: lifetime,
Locktime: vtxoTreeExpiry,
}

sweepScript, err := sweepClosure.Script()
Expand Down
6 changes: 3 additions & 3 deletions common/bitcointree/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ func UnspendableKey() *secp256k1.PublicKey {

// ValidateVtxoTree checks if the given vtxo tree is valid
// roundTxid & roundTxIndex & roundTxAmount are used to validate the root input outpoint
// serverPubkey & roundLifetime are used to validate the sweep tapscript leaves
// serverPubkey & vtxoTreeExpiry are used to validate the sweep tapscript leaves
// besides that, the function validates:
// - the number of nodes
// - the number of leaves
// - children coherence with parent
// - every control block and taproot output scripts
// - input and output amounts
func ValidateVtxoTree(
vtxoTree tree.VtxoTree, roundTx string, serverPubkey *secp256k1.PublicKey, roundLifetime common.RelativeLocktime,
vtxoTree tree.VtxoTree, roundTx string, serverPubkey *secp256k1.PublicKey, vtxoTreeExpiry common.RelativeLocktime,
) error {
roundTransaction, err := psbt.NewFromRawBytes(strings.NewReader(roundTx), true)
if err != nil {
Expand Down Expand Up @@ -126,7 +126,7 @@ func ValidateVtxoTree(

sweepClosure := &tree.CSVMultisigClosure{
MultisigClosure: tree.MultisigClosure{PubKeys: []*secp256k1.PublicKey{serverPubkey}},
Locktime: roundLifetime,
Locktime: vtxoTreeExpiry,
}

sweepScript, err := sweepClosure.Script()
Expand Down
46 changes: 23 additions & 23 deletions common/tree/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (

func BuildVtxoTree(
asset string, serverPubkey *secp256k1.PublicKey, receivers []VtxoLeaf,
feeSatsPerNode uint64, roundLifetime common.RelativeLocktime,
feeSatsPerNode uint64, vtxoTreeExpiry common.RelativeLocktime,
) (
factoryFn TreeFactory,
sharedOutputScript []byte, sharedOutputAmount uint64, err error,
) {
root, err := buildTreeNodes(
asset, serverPubkey, receivers, feeSatsPerNode, roundLifetime,
asset, serverPubkey, receivers, feeSatsPerNode, vtxoTreeExpiry,
)
if err != nil {
return
Expand All @@ -48,13 +48,13 @@ type vtxoOutput struct {
}

type node struct {
sweepKey *secp256k1.PublicKey
receivers []vtxoOutput
left *node
right *node
asset string
feeSats uint64
roundLifetime common.RelativeLocktime
sweepKey *secp256k1.PublicKey
receivers []vtxoOutput
left *node
right *node
asset string
feeSats uint64
vtxoTreeExpiry common.RelativeLocktime

_inputTaprootKey *secp256k1.PublicKey
_inputTaprootTree *taproot.IndexedElementsTapScriptTree
Expand Down Expand Up @@ -165,7 +165,7 @@ func (n *node) getWitnessData() (

sweepClosure := &CSVMultisigClosure{
MultisigClosure: MultisigClosure{PubKeys: []*secp256k1.PublicKey{n.sweepKey}},
Locktime: n.roundLifetime,
Locktime: n.vtxoTreeExpiry,
}

sweepLeaf, err := sweepClosure.Script()
Expand Down Expand Up @@ -381,7 +381,7 @@ func (n *node) buildVtxoTree() TreeFactory {

func buildTreeNodes(
asset string, serverPubkey *secp256k1.PublicKey, receivers []VtxoLeaf,
feeSatsPerNode uint64, roundLifetime common.RelativeLocktime,
feeSatsPerNode uint64, vtxoTreeExpiry common.RelativeLocktime,
) (root *node, err error) {
if len(receivers) == 0 {
return nil, fmt.Errorf("no receivers provided")
Expand All @@ -400,11 +400,11 @@ func buildTreeNodes(
}

leafNode := &node{
sweepKey: serverPubkey,
receivers: []vtxoOutput{{pubkey, r.Amount}},
asset: asset,
feeSats: feeSatsPerNode,
roundLifetime: roundLifetime,
sweepKey: serverPubkey,
receivers: []vtxoOutput{{pubkey, r.Amount}},
asset: asset,
feeSats: feeSatsPerNode,
vtxoTreeExpiry: vtxoTreeExpiry,
}
nodes = append(nodes, leafNode)
}
Expand Down Expand Up @@ -435,13 +435,13 @@ func createUpperLevel(nodes []*node) ([]*node, error) {
left := nodes[i]
right := nodes[i+1]
branchNode := &node{
sweepKey: left.sweepKey,
receivers: append(left.receivers, right.receivers...),
left: left,
right: right,
asset: left.asset,
feeSats: left.feeSats,
roundLifetime: left.roundLifetime,
sweepKey: left.sweepKey,
receivers: append(left.receivers, right.receivers...),
left: left,
right: right,
asset: left.asset,
feeSats: left.feeSats,
vtxoTreeExpiry: left.vtxoTreeExpiry,
}
pairs = append(pairs, branchNode)
}
Expand Down
10 changes: 5 additions & 5 deletions common/tree/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func UnspendableKey() *secp256k1.PublicKey {

// ValidateVtxoTree checks if the given vtxo tree is valid
// roundTxid & roundTxIndex & roundTxAmount are used to validate the root input outpoint
// serverPubkey & roundLifetime are used to validate the sweep tapscript leaves
// serverPubkey & vtxoTreeExpiry are used to validate the sweep tapscript leaves
// besides that, the function validates:
// - the number of nodes
// - the number of leaves
Expand All @@ -73,7 +73,7 @@ func UnspendableKey() *secp256k1.PublicKey {
// - input and output amounts
func ValidateVtxoTree(
tree VtxoTree, roundTx string, serverPubkey *secp256k1.PublicKey,
roundLifetime common.RelativeLocktime,
vtxoTreeExpiry common.RelativeLocktime,
) error {
roundTransaction, err := psetv2.NewPsetFromBase64(roundTx)
if err != nil {
Expand Down Expand Up @@ -136,7 +136,7 @@ func ValidateVtxoTree(
for _, level := range tree {
for _, node := range level {
if err := validateNodeTransaction(
node, tree, UnspendableKey(), serverPubkey, roundLifetime,
node, tree, UnspendableKey(), serverPubkey, vtxoTreeExpiry,
); err != nil {
return err
}
Expand All @@ -149,7 +149,7 @@ func ValidateVtxoTree(
func validateNodeTransaction(
node Node, tree VtxoTree,
expectedInternalKey, expectedServerPubkey *secp256k1.PublicKey,
expectedLifetime common.RelativeLocktime,
expectedVtxoTreeExpiry common.RelativeLocktime,
) error {
if node.Tx == "" {
return ErrNodeTxEmpty
Expand Down Expand Up @@ -244,7 +244,7 @@ func validateNodeTransaction(
schnorr.SerializePubKey(expectedServerPubkey),
)

isSweepDelay := c.Locktime == expectedLifetime
isSweepDelay := c.Locktime == expectedVtxoTreeExpiry

if isServer && !isSweepDelay {
return ErrInvalidSweepSequence
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.clark.regtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
- ARK_ROUND_INTERVAL=10
- ARK_NETWORK=regtest
- ARK_LOG_LEVEL=5
- ARK_ROUND_LIFETIME=20
- ARK_VTXO_TREE_EXPIRY=20
- ARK_TX_BUILDER_TYPE=covenantless
- ARK_ESPLORA_URL=http://chopsticks:3000
- ARK_NEUTRINO_PEER=bitcoin:18444
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.regtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
- ARK_NETWORK=liquidregtest
- ARK_LOG_LEVEL=5
- ARK_ESPLORA_URL=http://chopsticks-liquid:3000
- ARK_ROUND_LIFETIME=20
- ARK_VTXO_TREE_EXPIRY=20
- ARK_SCHEDULER_TYPE=block
- ARK_DB_TYPE=sqlite
- ARK_TX_BUILDER_TYPE=covenant
Expand Down
20 changes: 10 additions & 10 deletions pkg/client-sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ func (a *arkClient) initWithWallet(
return fmt.Errorf("failed to parse server pubkey: %s", err)
}

lifetimeType := common.LocktimeTypeBlock
if info.RoundLifetime >= 512 {
lifetimeType = common.LocktimeTypeSecond
vtxoTreeExpiryType := common.LocktimeTypeBlock
if info.VtxoTreeExpiry >= 512 {
vtxoTreeExpiryType = common.LocktimeTypeSecond
}

unilateralExitDelayType := common.LocktimeTypeBlock
Expand All @@ -168,7 +168,7 @@ func (a *arkClient) initWithWallet(
WalletType: args.Wallet.GetType(),
ClientType: args.ClientType,
Network: network,
RoundLifetime: common.RelativeLocktime{Type: lifetimeType, Value: uint32(info.RoundLifetime)},
VtxoTreeExpiry: common.RelativeLocktime{Type: vtxoTreeExpiryType, Value: uint32(info.VtxoTreeExpiry)},
RoundInterval: info.RoundInterval,
UnilateralExitDelay: common.RelativeLocktime{Type: unilateralExitDelayType, Value: uint32(info.UnilateralExitDelay)},
Dust: info.Dust,
Expand Down Expand Up @@ -229,9 +229,9 @@ func (a *arkClient) init(
return fmt.Errorf("failed to parse server pubkey: %s", err)
}

lifetimeType := common.LocktimeTypeBlock
if info.RoundLifetime >= 512 {
lifetimeType = common.LocktimeTypeSecond
vtxoTreeExpiryType := common.LocktimeTypeBlock
if info.VtxoTreeExpiry >= 512 {
vtxoTreeExpiryType = common.LocktimeTypeSecond
}

unilateralExitDelayType := common.LocktimeTypeBlock
Expand All @@ -245,7 +245,7 @@ func (a *arkClient) init(
WalletType: args.WalletType,
ClientType: args.ClientType,
Network: network,
RoundLifetime: common.RelativeLocktime{Type: lifetimeType, Value: uint32(info.RoundLifetime)},
VtxoTreeExpiry: common.RelativeLocktime{Type: vtxoTreeExpiryType, Value: uint32(info.VtxoTreeExpiry)},
RoundInterval: info.RoundInterval,
UnilateralExitDelay: common.RelativeLocktime{Type: unilateralExitDelayType, Value: uint32(info.UnilateralExitDelay)},
Dust: info.Dust,
Expand Down Expand Up @@ -373,8 +373,8 @@ func getWalletStore(storeType, datadir string) (walletstore.WalletStore, error)
}
}

func getCreatedAtFromExpiry(roundLifetime common.RelativeLocktime, expiry time.Time) time.Time {
return expiry.Add(-time.Duration(roundLifetime.Seconds()) * time.Second)
func getCreatedAtFromExpiry(vtxoTreeExpiry common.RelativeLocktime, expiry time.Time) time.Time {
return expiry.Add(-time.Duration(vtxoTreeExpiry.Seconds()) * time.Second)
}

func filterByOutpoints(vtxos []client.Vtxo, outpoints []client.Outpoint) []client.Vtxo {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client-sdk/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type TransportClient interface {

type Info struct {
PubKey string
RoundLifetime int64
VtxoTreeExpiry int64
UnilateralExitDelay int64
RoundInterval int64
Network string
Expand Down
2 changes: 1 addition & 1 deletion pkg/client-sdk/client/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (a *grpcClient) GetInfo(ctx context.Context) (*client.Info, error) {
}
return &client.Info{
PubKey: resp.GetPubkey(),
RoundLifetime: resp.GetRoundLifetime(),
VtxoTreeExpiry: resp.GetVtxoTreeExpiry(),
UnilateralExitDelay: resp.GetUnilateralExitDelay(),
RoundInterval: resp.GetRoundInterval(),
Network: resp.GetNetwork(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/client-sdk/client/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (a *restClient) GetInfo(
return nil, err
}

roundLifetime, err := strconv.Atoi(resp.Payload.RoundLifetime)
vtxoTreeExpiry, err := strconv.Atoi(resp.Payload.VtxoTreeExpiry)
if err != nil {
return nil, err
}
Expand All @@ -87,7 +87,7 @@ func (a *restClient) GetInfo(

return &client.Info{
PubKey: resp.Payload.Pubkey,
RoundLifetime: int64(roundLifetime),
VtxoTreeExpiry: int64(vtxoTreeExpiry),
UnilateralExitDelay: int64(unilateralExitDelay),
RoundInterval: int64(roundInterval),
Network: resp.Payload.Network,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4b6c851

Please sign in to comment.