* Cleanup common

* Cleanup client

* Cleanup server

* Renamings

* Tidy up proto

* Update ocean protos

* Fixes

* Fixes
This commit is contained in:
Pietralberto Mazza
2024-02-28 18:05:03 +01:00
committed by GitHub
parent 1650ea5935
commit 6d0d03e316
31 changed files with 2475 additions and 2217 deletions

View File

@@ -372,11 +372,11 @@
"pubkey": {
"type": "string"
},
"lifetime": {
"roundLifetime": {
"type": "string",
"format": "int64"
},
"exitDelay": {
"unilateralExitDelay": {
"type": "string",
"format": "int64"
}

View File

@@ -169,6 +169,15 @@
}
}
},
"v1LockUtxosResponse": {
"type": "object",
"properties": {
"expirationDate": {
"type": "string",
"format": "int64"
}
}
},
"v1MintResponse": {
"type": "object",
"properties": {

View File

@@ -56,15 +56,6 @@ service ArkService {
}
}
message OnboardRequest {
string boarding_tx = 1;
Tree congestion_tree = 2;
string user_pubkey = 3;
}
message OnboardResponse {
}
message RegisterPaymentRequest {
repeated Input inputs = 1;
}
@@ -94,6 +85,63 @@ message GetRoundResponse {
Round round = 1;
}
message GetEventStreamRequest {}
message GetEventStreamResponse {
oneof event {
RoundFinalizationEvent round_finalization = 1;
RoundFinalizedEvent round_finalized = 2;
RoundFailed round_failed = 3;
}
}
message PingRequest {
string payment_id = 1;
}
message PingResponse {}
message ListVtxosRequest {
string address = 1;
}
message ListVtxosResponse {
repeated Vtxo vtxos = 1;
}
message GetInfoRequest {}
message GetInfoResponse {
string pubkey = 1;
int64 round_lifetime = 2;
int64 unilateral_exit_delay = 3;
}
message OnboardRequest {
string boarding_tx = 1;
Tree congestion_tree = 2;
string user_pubkey = 3;
}
message OnboardResponse {
}
// EVENT TYPES
message RoundFinalizationEvent {
string id = 1;
string pool_partial_tx = 2;
repeated string forfeit_txs = 3;
Tree congestion_tree = 4;
}
message RoundFinalizedEvent {
string id = 1;
string pool_txid = 2;
}
message RoundFailed {
string id = 1;
string reason = 2;
}
// TYPES
message Round {
string id = 1;
int64 start = 2;
@@ -114,13 +162,6 @@ message Output {
uint64 amount = 2;
}
message RoundFinalizationEvent {
string id = 1;
string pool_partial_tx = 2;
repeated string forfeit_txs = 3;
Tree congestion_tree = 4;
}
message Tree {
repeated TreeLevel levels = 1;
}
@@ -135,51 +176,9 @@ message Node {
string parent_txid = 3;
}
message RoundFinalizedEvent {
string id = 1;
string pool_txid = 2;
}
message RoundFailed {
string id = 1;
string reason = 2;
}
message GetEventStreamRequest {}
message GetEventStreamResponse {
oneof event {
RoundFinalizationEvent round_finalization = 1;
RoundFinalizedEvent round_finalized = 2;
RoundFailed round_failed = 3;
}
}
message PingRequest {
string payment_id = 1;
}
message PingResponse {}
message ListVtxosRequest {
string address = 1;
}
message ListVtxosResponse {
repeated Vtxo vtxos = 1;
}
message Vtxo {
Input outpoint = 1;
Output receiver = 2;
bool spent = 3;
string pool_txid = 4;
}
message GetInfoRequest {}
message GetInfoResponse {
string pubkey = 1;
int64 lifetime = 2;
int64 exit_delay = 3;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -25,6 +25,8 @@ type TransactionServiceClient interface {
// Selected utxos are locked for predefined amount of time to prevent
// double-spending them.
SelectUtxos(ctx context.Context, in *SelectUtxosRequest, opts ...grpc.CallOption) (*SelectUtxosResponse, error)
// LockUtxos allows to manually select utxos to spend by a subsequent tx.
LockUtxos(ctx context.Context, in *LockUtxosRequest, opts ...grpc.CallOption) (*LockUtxosResponse, error)
// EstimateFees returns the fee amount to pay for a tx containing the given
// inputs and outputs.
EstimateFees(ctx context.Context, in *EstimateFeesRequest, opts ...grpc.CallOption) (*EstimateFeesResponse, error)
@@ -87,6 +89,15 @@ func (c *transactionServiceClient) SelectUtxos(ctx context.Context, in *SelectUt
return out, nil
}
func (c *transactionServiceClient) LockUtxos(ctx context.Context, in *LockUtxosRequest, opts ...grpc.CallOption) (*LockUtxosResponse, error) {
out := new(LockUtxosResponse)
err := c.cc.Invoke(ctx, "/ocean.v1.TransactionService/LockUtxos", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *transactionServiceClient) EstimateFees(ctx context.Context, in *EstimateFeesRequest, opts ...grpc.CallOption) (*EstimateFeesResponse, error) {
out := new(EstimateFeesResponse)
err := c.cc.Invoke(ctx, "/ocean.v1.TransactionService/EstimateFees", in, out, opts...)
@@ -224,6 +235,8 @@ type TransactionServiceServer interface {
// Selected utxos are locked for predefined amount of time to prevent
// double-spending them.
SelectUtxos(context.Context, *SelectUtxosRequest) (*SelectUtxosResponse, error)
// LockUtxos allows to manually select utxos to spend by a subsequent tx.
LockUtxos(context.Context, *LockUtxosRequest) (*LockUtxosResponse, error)
// EstimateFees returns the fee amount to pay for a tx containing the given
// inputs and outputs.
EstimateFees(context.Context, *EstimateFeesRequest) (*EstimateFeesResponse, error)
@@ -270,6 +283,9 @@ func (UnimplementedTransactionServiceServer) GetTransaction(context.Context, *Ge
func (UnimplementedTransactionServiceServer) SelectUtxos(context.Context, *SelectUtxosRequest) (*SelectUtxosResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SelectUtxos not implemented")
}
func (UnimplementedTransactionServiceServer) LockUtxos(context.Context, *LockUtxosRequest) (*LockUtxosResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method LockUtxos not implemented")
}
func (UnimplementedTransactionServiceServer) EstimateFees(context.Context, *EstimateFeesRequest) (*EstimateFeesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method EstimateFees not implemented")
}
@@ -360,6 +376,24 @@ func _TransactionService_SelectUtxos_Handler(srv interface{}, ctx context.Contex
return interceptor(ctx, in, info, handler)
}
func _TransactionService_LockUtxos_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LockUtxosRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TransactionServiceServer).LockUtxos(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/ocean.v1.TransactionService/LockUtxos",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TransactionServiceServer).LockUtxos(ctx, req.(*LockUtxosRequest))
}
return interceptor(ctx, in, info, handler)
}
func _TransactionService_EstimateFees_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(EstimateFeesRequest)
if err := dec(in); err != nil {
@@ -627,6 +661,10 @@ var TransactionService_ServiceDesc = grpc.ServiceDesc{
MethodName: "SelectUtxos",
Handler: _TransactionService_SelectUtxos_Handler,
},
{
MethodName: "LockUtxos",
Handler: _TransactionService_LockUtxos_Handler,
},
{
MethodName: "EstimateFees",
Handler: _TransactionService_EstimateFees_Handler,

View File

@@ -31,18 +31,6 @@ func main() {
NoTLS: cfg.NoTLS,
}
if cfg.RoundLifetime%512 != 0 {
setLifetime := cfg.RoundLifetime
cfg.RoundLifetime = cfg.RoundLifetime - (cfg.RoundLifetime % 512)
log.Infof("round lifetime must be a multiple of 512, %d -> %d", setLifetime, cfg.RoundLifetime)
}
if cfg.ExitDelay%512 != 0 {
setExitDelay := cfg.ExitDelay
cfg.ExitDelay = cfg.ExitDelay - (cfg.ExitDelay % 512)
log.Infof("exit delay must be a multiple of 512, %d -> %d", setExitDelay, cfg.ExitDelay)
}
appConfig := &appconfig.Config{
DbType: cfg.DbType,
DbDir: cfg.DbDir,
@@ -54,7 +42,7 @@ func main() {
WalletAddr: cfg.WalletAddr,
MinRelayFee: cfg.MinRelayFee,
RoundLifetime: cfg.RoundLifetime,
ExitDelay: cfg.ExitDelay,
UnilateralExitDelay: cfg.UnilateralExitDelay,
}
svc, err := grpcservice.NewService(svcConfig, appConfig)
if err != nil {

View File

@@ -15,6 +15,8 @@ import (
"github.com/vulpemventures/go-elements/network"
)
const minAllowedSequence = 512
var (
supportedDbs = supportedType{
"badger": {},
@@ -41,7 +43,7 @@ type Config struct {
WalletAddr string
MinRelayFee uint64
RoundLifetime int64
ExitDelay int64
UnilateralExitDelay int64
repo ports.RepoManager
svc application.Service
@@ -95,25 +97,32 @@ func (c *Config) Validate() error {
return err
}
// round life time must be a multiple of 512
if c.RoundLifetime < 512 || c.RoundLifetime%512 != 0 {
return fmt.Errorf("invalid round lifetime, must be greater or equal than 512 and a multiple of 512")
}
seq, err := common.BIP68Encode(uint(c.RoundLifetime))
if err != nil {
return fmt.Errorf("invalid round lifetime, %s", err)
if c.RoundLifetime < minAllowedSequence {
return fmt.Errorf(
"invalid round lifetime, must be a at least %d", minAllowedSequence,
)
}
seconds, err := common.BIP68Decode(seq)
if err != nil {
return fmt.Errorf("invalid round lifetime, %s", err)
if c.UnilateralExitDelay < minAllowedSequence {
return fmt.Errorf(
"invalid unilateral exit delay, must at least %d", minAllowedSequence,
)
}
if seconds != uint(c.RoundLifetime) {
return fmt.Errorf("invalid round lifetime, must be a multiple of 512")
if c.RoundLifetime%minAllowedSequence != 0 {
c.RoundLifetime -= c.RoundLifetime % minAllowedSequence
log.Infof(
"round lifetime must be a multiple of %d, rounded to %d",
minAllowedSequence, c.RoundLifetime,
)
}
if c.ExitDelay < 512 || c.ExitDelay%512 != 0 {
return fmt.Errorf("invalid exit delay, must be greater or equal than 512 and a multiple of 512")
if c.UnilateralExitDelay%minAllowedSequence != 0 {
c.UnilateralExitDelay -= c.UnilateralExitDelay % minAllowedSequence
log.Infof(
"unilateral exit delay must be a multiple of %d, rounded to %d",
minAllowedSequence, c.UnilateralExitDelay,
)
}
return nil
@@ -166,7 +175,9 @@ func (c *Config) txBuilderService() error {
switch c.TxBuilderType {
case "covenant":
svc = txbuilder.NewTxBuilder(c.wallet, net, c.RoundLifetime, c.ExitDelay)
svc = txbuilder.NewTxBuilder(
c.wallet, net, c.RoundLifetime, c.UnilateralExitDelay,
)
default:
err = fmt.Errorf("unknown tx builder type")
}
@@ -215,7 +226,8 @@ func (c *Config) schedulerService() error {
func (c *Config) appService() error {
net := c.mainChain()
svc, err := application.NewService(
c.Network, net, c.RoundInterval, c.RoundLifetime, c.ExitDelay, c.MinRelayFee,
c.Network, net,
c.RoundInterval, c.RoundLifetime, c.UnilateralExitDelay, c.MinRelayFee,
c.wallet, c.repo, c.txBuilder, c.scanner, c.scheduler,
)
if err != nil {

View File

@@ -24,7 +24,7 @@ type Config struct {
LogLevel int
MinRelayFee uint64
RoundLifetime int64
ExitDelay int64
UnilateralExitDelay int64
}
var (
@@ -41,7 +41,7 @@ var (
Network = "NETWORK"
MinRelayFee = "MIN_RELAY_FEE"
RoundLifetime = "ROUND_LIFETIME"
ExitDelay = "EXIT_DELAY"
UnilateralExitDelay = "UNILATERAL_EXIT_DELAY"
defaultDatadir = common.AppDataDir("arkd", false)
defaultRoundInterval = 10
@@ -55,7 +55,7 @@ var (
defaultLogLevel = 5
defaultMinRelayFee = 30
defaultRoundLifetime = 512
defaultExitDelay = 512
defaultUnilateralExitDelay = 512
)
func LoadConfig() (*Config, error) {
@@ -74,7 +74,7 @@ func LoadConfig() (*Config, error) {
viper.SetDefault(Network, defaultNetwork)
viper.SetDefault(RoundLifetime, defaultRoundLifetime)
viper.SetDefault(MinRelayFee, defaultMinRelayFee)
viper.SetDefault(ExitDelay, defaultExitDelay)
viper.SetDefault(UnilateralExitDelay, defaultUnilateralExitDelay)
net, err := getNetwork()
if err != nil {
@@ -99,7 +99,7 @@ func LoadConfig() (*Config, error) {
Network: net,
MinRelayFee: viper.GetUint64(MinRelayFee),
RoundLifetime: viper.GetInt64(RoundLifetime),
ExitDelay: viper.GetInt64(ExitDelay),
UnilateralExitDelay: viper.GetInt64(UnilateralExitDelay),
}, nil
}

View File

@@ -38,13 +38,13 @@ type Service interface {
}
type service struct {
network common.Network
onchainNework network.Network
pubkey *secp256k1.PublicKey
roundLifetime int64
roundInterval int64
minRelayFee uint64
exitDelay int64
network common.Network
onchainNework network.Network
pubkey *secp256k1.PublicKey
roundLifetime int64
roundInterval int64
unilateralExitDelay int64
minRelayFee uint64
wallet ports.WalletService
repoManager ports.RepoManager
@@ -60,7 +60,7 @@ type service struct {
func NewService(
network common.Network, onchainNetwork network.Network,
roundInterval, roundLifetime int64, exitDelay int64, minRelayFee uint64,
roundInterval, roundLifetime, unilateralExitDelay int64, minRelayFee uint64,
walletSvc ports.WalletService, repoManager ports.RepoManager,
builder ports.TxBuilder, scanner ports.BlockchainScanner,
scheduler ports.SchedulerService,
@@ -79,7 +79,7 @@ func NewService(
svc := &service{
network, onchainNetwork, pubkey,
roundLifetime, roundInterval, minRelayFee, exitDelay,
roundLifetime, roundInterval, unilateralExitDelay, minRelayFee,
walletSvc, repoManager, builder, scanner, sweeper,
paymentRequests, forfeitTxs, eventsCh,
}
@@ -181,7 +181,8 @@ func (s *service) GetRoundByTxid(ctx context.Context, poolTxid string) (*domain.
}
func (s *service) GetInfo(ctx context.Context) (string, int64, int64, error) {
return hex.EncodeToString(s.pubkey.SerializeCompressed()), s.roundLifetime, s.exitDelay, nil
pubkey := hex.EncodeToString(s.pubkey.SerializeCompressed())
return pubkey, s.roundLifetime, s.unilateralExitDelay, nil
}
func (s *service) Onboard(

View File

@@ -20,10 +20,10 @@ import (
)
const (
testingKey = "0218d5ca8b58797b7dbd65c075dd7ba7784b3f38ab71b1a5a8e3f94ba0257654a6"
minRelayFee = uint64(30)
roundLifetime = int64(1209344)
exitDelay = int64(512)
testingKey = "0218d5ca8b58797b7dbd65c075dd7ba7784b3f38ab71b1a5a8e3f94ba0257654a6"
minRelayFee = uint64(30)
roundLifetime = int64(1209344)
unilateralExitDelay = int64(512)
)
var (
@@ -45,7 +45,9 @@ func TestMain(m *testing.M) {
}
func TestBuildPoolTx(t *testing.T) {
builder := txbuilder.NewTxBuilder(wallet, network.Liquid, roundLifetime, exitDelay)
builder := txbuilder.NewTxBuilder(
wallet, network.Liquid, roundLifetime, unilateralExitDelay,
)
fixtures, err := parsePoolTxFixtures()
require.NoError(t, err)
@@ -54,14 +56,18 @@ func TestBuildPoolTx(t *testing.T) {
if len(fixtures.Valid) > 0 {
t.Run("valid", func(t *testing.T) {
for _, f := range fixtures.Valid {
poolTx, congestionTree, err := builder.BuildPoolTx(pubkey, f.Payments, minRelayFee)
poolTx, congestionTree, err := builder.BuildPoolTx(
pubkey, f.Payments, minRelayFee,
)
require.NoError(t, err)
require.NotEmpty(t, poolTx)
require.NotEmpty(t, congestionTree)
require.Equal(t, f.ExpectedNumOfNodes, congestionTree.NumberOfNodes())
require.Len(t, congestionTree.Leaves(), f.ExpectedNumOfLeaves)
err = tree.ValidateCongestionTree(congestionTree, poolTx, pubkey, roundLifetime)
err = tree.ValidateCongestionTree(
congestionTree, poolTx, pubkey, roundLifetime,
)
require.NoError(t, err)
}
})
@@ -70,7 +76,9 @@ func TestBuildPoolTx(t *testing.T) {
if len(fixtures.Invalid) > 0 {
t.Run("invalid", func(t *testing.T) {
for _, f := range fixtures.Invalid {
poolTx, congestionTree, err := builder.BuildPoolTx(pubkey, f.Payments, minRelayFee)
poolTx, congestionTree, err := builder.BuildPoolTx(
pubkey, f.Payments, minRelayFee,
)
require.EqualError(t, err, f.ExpectedErr)
require.Empty(t, poolTx)
require.Empty(t, congestionTree)
@@ -80,7 +88,9 @@ func TestBuildPoolTx(t *testing.T) {
}
func TestBuildForfeitTxs(t *testing.T) {
builder := txbuilder.NewTxBuilder(wallet, network.Liquid, 1209344, exitDelay)
builder := txbuilder.NewTxBuilder(
wallet, network.Liquid, 1209344, unilateralExitDelay,
)
fixtures, err := parseForfeitTxsFixtures()
require.NoError(t, err)

View File

@@ -203,9 +203,9 @@ func (h *handler) GetInfo(ctx context.Context, req *arkv1.GetInfoRequest) (*arkv
}
return &arkv1.GetInfoResponse{
Pubkey: pubkey,
Lifetime: lifetime,
ExitDelay: delay,
Pubkey: pubkey,
RoundLifetime: lifetime,
UnilateralExitDelay: delay,
}, nil
}