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

Add batch creation timestamp, remove order max duration, rename batch version fields #193

Closed
wants to merge 4 commits into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions account/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ func (a *mockAuctioneer) SubscribeAccountUpdates(_ context.Context,

func (a *mockAuctioneer) Terms(context.Context) (*terms.AuctioneerTerms, error) {
return &terms.AuctioneerTerms{
MaxAccountValue: maxAccountValue,
MaxOrderDuration: maxAccountExpiry,
MaxAccountValue: maxAccountValue,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion auctioneer/account_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (s *acctSubscription) authenticate(ctx context.Context) error {
Msg: &poolrpc.ClientAuctionMessage_Commit{
Commit: &poolrpc.AccountCommitment{
CommitHash: s.commitHash[:],
BatchVersion: uint32(order.CurrentVersion),
BatchVersion: uint32(order.CurrentBatchVersion),
},
},
})
Expand Down
1 change: 0 additions & 1 deletion auctioneer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,6 @@ func (c *Client) Terms(ctx context.Context) (*terms.AuctioneerTerms, error) {

return &terms.AuctioneerTerms{
MaxAccountValue: btcutil.Amount(resp.MaxAccountValue),
MaxOrderDuration: resp.MaxOrderDurationBlocks,
OrderExecBaseFee: btcutil.Amount(resp.ExecutionFee.BaseFee),
OrderExecFeeRate: btcutil.Amount(resp.ExecutionFee.FeeRate),
LeaseDurations: resp.LeaseDurations,
Expand Down
7 changes: 2 additions & 5 deletions clientdb/batch_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func getSnapshotBuckets(tx *bbolt.Tx) (*bbolt.Bucket, *bbolt.Bucket,

func serializeLocalBatchSnapshot(w io.Writer, b *LocalBatchSnapshot) error {
err := WriteElements(
w, uint32(b.Version), b.BatchID[:], b.ClearingPrice,
w, b.Version, b.BatchID[:], b.ClearingPrice,
b.ExecutionFee, b.BatchTX, b.BatchTxFeeRate,
)
if err != nil {
Expand Down Expand Up @@ -447,17 +447,14 @@ func serializeLocalBatchSnapshot(w io.Writer, b *LocalBatchSnapshot) error {

func deserializeLocalBatchSnapshot(r io.Reader) (*LocalBatchSnapshot, error) {
b := &LocalBatchSnapshot{}
var version uint32
err := ReadElements(
r, &version, b.BatchID[:], &b.ClearingPrice, &b.ExecutionFee,
r, &b.Version, b.BatchID[:], &b.ClearingPrice, &b.ExecutionFee,
&b.BatchTX, &b.BatchTxFeeRate,
)
if err != nil {
return nil, err
}

b.Version = order.BatchVersion(version)

b.Accounts, err = deserializeAccounts(r)
if err != nil {
return nil, err
Expand Down
21 changes: 21 additions & 0 deletions clientdb/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"reflect"
"time"

"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
Expand Down Expand Up @@ -58,6 +59,9 @@ func WriteElement(w io.Writer, element interface{}) error {
case order.Version:
return lnwire.WriteElement(w, uint32(e))

case order.BatchVersion:
return lnwire.WriteElement(w, uint32(e))

case order.Type:
return lnwire.WriteElement(w, uint8(e))

Expand Down Expand Up @@ -103,6 +107,9 @@ func WriteElement(w io.Writer, element interface{}) error {
case [32]byte:
return lnwire.WriteElement(w, e[:])

case time.Time:
return lnwire.WriteElement(w, uint64(e.UnixNano()))

case *wire.MsgTx:
if err := e.Serialize(w); err != nil {
return err
Expand Down Expand Up @@ -152,6 +159,13 @@ func ReadElement(r io.Reader, element interface{}) error { // nolint:gocyclo
}
*e = order.Version(v)

case *order.BatchVersion:
var v uint32
if err := lnwire.ReadElement(r, &v); err != nil {
return err
}
*e = order.BatchVersion(v)

case *order.Type:
var v uint8
if err := lnwire.ReadElement(r, &v); err != nil {
Expand Down Expand Up @@ -235,6 +249,13 @@ func ReadElement(r io.Reader, element interface{}) error { // nolint:gocyclo
return err
}

case *time.Time:
var ns uint64
if err := lnwire.ReadElement(r, &ns); err != nil {
return err
}
*e = time.Unix(0, int64(ns))

case **wire.MsgTx:
var tx wire.MsgTx
if err := tx.Deserialize(r); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions order/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ const (
type BatchVersion uint32

const (
// DefaultVersion is the first implemented version of the batch
// DefaultBatchVersion is the first implemented version of the batch
// verification protocol.
DefaultVersion BatchVersion = 0
DefaultBatchVersion BatchVersion = 0

// CurrentVersion must point to the latest implemented version of the
// CurrentBatchVersion must point to the latest implemented version of the
// batch verification protocol. Both server and client should always
// refer to this constant. If a client's binary is not updated in time
// it will point to a previous version than the server and the mismatch
// will be detected during the OrderMatchPrepare call.
CurrentVersion = DefaultVersion
CurrentBatchVersion = DefaultBatchVersion
)

// BatchID is a 33-byte point that uniquely identifies this batch. This ID
Expand Down
2 changes: 1 addition & 1 deletion order/batch_storer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestBatchStorer(t *testing.T) {
}
batch := &Batch{
ID: batchID,
Version: DefaultVersion,
Version: DefaultBatchVersion,
MatchedOrders: matchedOrders,
AccountDiffs: accountDiffs,
BatchTX: batchTx,
Expand Down
2 changes: 1 addition & 1 deletion order/batch_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (v *batchVerifier) Verify(batch *Batch) error {
// as the server. Otherwise we bail out of the batch. This should
// already be handled when the client connects/authenticates. But
// doesn't hurt to check again.
if batch.Version != CurrentVersion {
if batch.Version != CurrentBatchVersion {
return ErrVersionMismatch
}

Expand Down
2 changes: 1 addition & 1 deletion order/batch_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func TestBatchVerifier(t *testing.T) {
}
batch := &Batch{
ID: batchID,
Version: DefaultVersion,
Version: DefaultBatchVersion,
MatchedOrders: matchedOrders,
AccountDiffs: accountDiffs,
ExecutionFee: terms.NewLinearFeeSchedule(
Expand Down
7 changes: 1 addition & 6 deletions order/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
// ErrVersionMismatch is the error that is returned if we don't
// implement the same batch verification version as the server.
ErrVersionMismatch = fmt.Errorf("version %d mismatches server version",
CurrentVersion)
CurrentBatchVersion)
)

// ManagerConfig contains all of the required dependencies for the Manager to
Expand Down Expand Up @@ -202,11 +202,6 @@ func (m *Manager) validateOrder(order Order, acct *account.Account,
return fmt.Errorf("invalid lease duration, must be "+
"at least %d", MinimumOrderDurationBlocks)
}
if order.Details().LeaseDuration > terms.MaxOrderDuration {
return fmt.Errorf("invalid lease duration, must be "+
"smaller than or equal to %d",
terms.MaxOrderDuration)
}
if order.Details().LeaseDuration%MinimumOrderDurationBlocks != 0 {
return fmt.Errorf("invalid lease duration, must be "+
"multiple of %d", MinimumOrderDurationBlocks)
Expand Down
1 change: 0 additions & 1 deletion order/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func TestValidateOrderAccountIsolation(t *testing.T) {
}

testTerms := &terms.AuctioneerTerms{
MaxOrderDuration: 100 * MinimumOrderDurationBlocks,
OrderExecBaseFee: 1,
OrderExecFeeRate: 100,
}
Expand Down
Loading