Skip to content

Commit

Permalink
Light Node feature added. (#1254)
Browse files Browse the repository at this point in the history
* Light Node feature added.

* Ride V8 library version added. Tests updated. (#1255)

* Ride V8 library version added. Tests updated.

* Replaced map initialization with for cycle.

* Some BigInt functions revaluated. Function removeByIndex revaluated. (#1256)

* Add attachment field in order (#1140)

* add attachment field in order

* fix tests

* Add more info to the error message. Refactor a bit 'TestAttachmentInOrder'.

* add new feature and ride v8 for attachment in order

* Correct features order ('TransactionStateSnapshot' == 22).

* Bound exising logic to 'TransactionStateSnapshot' feature (version 1.5.0) according to the NODE-2531 task.

* fix sign for order with attachment

* fix issues and add tests

* fix linters issues

* create type for order's version

* add test for order with rideV8

* Replace type alias with type for OrderVersion.

* Type of the attachment in the Ride Order type updated to "ByteVector|Unit".

* Old feature naming removed.
Existing function Size of Attachement used to check the length of order's attachement.

* Comments fixed.
Obsolete TODO removed.

---------

Co-authored-by: Nikolay Eskov <[email protected]>
Co-authored-by: Alexey Kiselev <[email protected]>

* Ride function replaceByIndex implemented and tested. (#1257)

* Ride function replaceByIndex implemented and tested.

* Arguments checks of list functions replaced by call to checkArgs function.
Constant moved to function where it used.
Functions max and min renamed to listMax and listMin because of the collision with built-in functions.

* CalculateDelay Ride function implemented and partially tested. (#1259)

* CalculateDelay Ride function implemented and partially tested.

* Funciton calculateDelay updated according to new specification. Tests added.

* Irrelevant comment removed.
New function ID fixed.

* Tests on correct scopes handling by estimator and evaluator added. (#1264)

* Tests on correct scopes handling by estimator and evaluator added.
Few compilation errors of FOLD fixed.
Comparison of Any type to other types fixed in compilation.

* Added test on FOLD compilation.
Fixed SimpeType Equal function.

* Deactivation of Ride versions 1, 2 and 3 on Light Node feature activation implemented. (#1278)

Test added.

---------

Co-authored-by: Anton Ilin <[email protected]>
Co-authored-by: Nikolay Eskov <[email protected]>

* Transaction version validation restored after activation on feature 22. (#1346)

* Transaction version validation restored after activation on feature 22.

* Fixed checkVersion parameter initialization.

* Linter issues fixed for verifier.go.

* Exchange transaction validation functions linter issues were fixed.

* Simplified verification of Exchange transactions by interface type.

* Stringer added to TransactionType for correct naming of transactions in API error messages.
Simplified switch-case in verifier with private interface for transactions that supports Verify function.

* Made Light Node feature disabled. It will be turned on in separate PR.

* Error message improved. Comment fixed.

---------

Co-authored-by: Nikolay Eskov <[email protected]>
Co-authored-by: Anton Ilin <[email protected]>
  • Loading branch information
3 people authored Apr 12, 2024
1 parent 61d52d6 commit 85fc27e
Show file tree
Hide file tree
Showing 57 changed files with 2,349 additions and 733 deletions.
18 changes: 7 additions & 11 deletions pkg/consensus/pos_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import (
"math/big"

"github.com/pkg/errors"

"github.com/wavesplatform/gowaves/pkg/crypto"
"github.com/wavesplatform/gowaves/pkg/types"
)

const (
HitSize = 8
MinBaseTarget = 9

nxtPosHeightDiffForHit = 0
fairPosHeightDiffForHit = 100
hitSize = 8
MinBaseTarget = 9

// Nxt values.
minBlockDelaySeconds = 53
Expand All @@ -30,10 +32,6 @@ const (

type Hit = big.Int

var (
maxSignature = bytes.Repeat([]byte{0xff}, hitSize)
)

var (
NXTPosCalculator = PosCalculator(&nxtPosCalculator{})
FairPosCalculatorV1 = NewFairPosCalculator(delayDeltaV1, tMinV1)
Expand Down Expand Up @@ -136,8 +134,8 @@ func (p *vrfGenerationSignatureProvider) VerifyGenerationSignature(pk crypto.Pub
}

func GenHit(source []byte) (*Hit, error) {
s := [hitSize]byte{}
copy(s[:], source[:hitSize])
s := [HitSize]byte{}
copy(s[:], source[:HitSize])
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
Expand Down Expand Up @@ -219,10 +217,8 @@ type fairPosCalculator struct {
}

func (calc *fairPosCalculator) CalculateDelay(hit *Hit, confirmedTarget types.BaseTarget, balance uint64) (uint64, error) {
var maxHit big.Int
maxHit.SetBytes(maxSignature)
var maxHitFloat big.Float
maxHitFloat.SetInt(&maxHit)
maxHitFloat.SetUint64(math.MaxUint64)
var hitFloat big.Float
hitFloat.SetInt(hit)
var quo big.Float
Expand Down
8 changes: 7 additions & 1 deletion pkg/grpc/server/transactions_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
g "github.com/wavesplatform/gowaves/pkg/grpc/generated/waves/node/grpc"
"github.com/wavesplatform/gowaves/pkg/node/messages"
"github.com/wavesplatform/gowaves/pkg/proto"
"github.com/wavesplatform/gowaves/pkg/settings"
"github.com/wavesplatform/gowaves/pkg/state"
"github.com/wavesplatform/gowaves/pkg/util/iterators"
)
Expand Down Expand Up @@ -230,7 +231,12 @@ func (s *Server) Broadcast(ctx context.Context, tx *pb.SignedTransaction) (out *
if err != nil {
return nil, apiError(err)
}
t, err = t.Validate(s.scheme)
lightNodeActivated, err := s.state.IsActivated(int16(settings.LightNode))
if err != nil {
return nil, apiError(err)
}
vp := proto.TransactionValidationParams{Scheme: s.scheme, CheckVersion: lightNodeActivated}
t, err = t.Validate(vp)
if err != nil {
return nil, apiError(err)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/miner/utxpool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (a transaction) GetID(_ proto.Scheme) ([]byte, error) {
return a.id, nil
}

func (transaction) Validate(_ proto.Scheme) (proto.Transaction, error) {
func (transaction) Validate(proto.TransactionValidationParams) (proto.Transaction, error) {
panic("not implemented")
}

Expand Down Expand Up @@ -87,6 +87,10 @@ func (transaction) GetTypeInfo() proto.TransactionTypeInfo {
panic("not implemented")
}

func (transaction) GetType() proto.TransactionType {
panic("not implemented")
}

func (transaction) GetVersion() byte {
panic("not implemented")
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/node/fsm/fsm_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/wavesplatform/gowaves/pkg/p2p/peer"
"github.com/wavesplatform/gowaves/pkg/p2p/peer/extension"
"github.com/wavesplatform/gowaves/pkg/proto"
"github.com/wavesplatform/gowaves/pkg/settings"
)

const (
Expand Down Expand Up @@ -119,7 +120,12 @@ func tryBroadcastTransaction(
}
}()
}
if _, err = t.Validate(baseInfo.scheme); err != nil {
lightNodeActivated, err := baseInfo.storage.IsActivated(int16(settings.LightNode))
if err != nil {
return fsm, nil, errors.Wrap(err, "failed to check if LightNode feature is activated")
}
params := proto.TransactionValidationParams{Scheme: baseInfo.scheme, CheckVersion: lightNodeActivated}
if _, err = t.Validate(params); err != nil {
err = errors.Wrap(err, "failed to validate transaction")
if p != nil {
baseInfo.peers.AddToBlackList(p, time.Now(), err.Error())
Expand Down
11 changes: 7 additions & 4 deletions pkg/proto/eth_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ func (tx *EthereumTransaction) GetTypeInfo() TransactionTypeInfo {
}
}

func (tx *EthereumTransaction) GetType() TransactionType {
return EthereumMetamaskTransaction
}

func (tx *EthereumTransaction) GetVersion() byte {
// EthereumTransaction version always should be 1
return 1
Expand Down Expand Up @@ -317,15 +321,14 @@ func (tx *EthereumTransaction) Verify() (*EthereumPublicKey, error) {

// Validate performs basic checks for EthereumTransaction according to the specification
// This method doesn't include signature verification. Use Verify method for signature verification
func (tx *EthereumTransaction) Validate(scheme Scheme) (Transaction, error) {
func (tx *EthereumTransaction) Validate(params TransactionValidationParams) (Transaction, error) {
// same chainID
if tx.ChainId().Cmp(big.NewInt(int64(scheme))) != 0 {
if tx.ChainId().Cmp(big.NewInt(int64(params.Scheme))) != 0 {
// TODO: introduce new error type for scheme validation
txChainID := tx.ChainId().Uint64()
return tx, errs.NewTxValidationError(fmt.Sprintf(
"Address belongs to another network: expected: %d(%c), actual: %d(%c)",
scheme, scheme,
txChainID, txChainID,
params.Scheme, params.Scheme, txChainID, txChainID,
))
}
// accept only EthereumLegacyTxType (this check doesn't exist in scala)
Expand Down
3 changes: 2 additions & 1 deletion pkg/proto/protobuf_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ func (c *ProtobufConverter) extractOrder(o *g.Order) Order {
c.err = errors.New("empty order")
return nil
}
orderVersion := c.byte(o.Version)
orderVersion := OrderVersion(c.byte(o.Version))
priceMode, err := c.orderPriceMode(o.PriceMode)
if err != nil {
c.err = err
Expand Down Expand Up @@ -756,6 +756,7 @@ func (c *ProtobufConverter) extractOrder(o *g.Order) Order {
OrderBody: body,
MatcherFeeAsset: c.extractOptionalAsset(o.MatcherFee),
PriceMode: priceMode,
Attachment: c.attachment(o.Attachment),
}
if sig, ok := o.Sender.(*g.Order_Eip712Signature); ok {
ethOrder := EthereumOrderV4{
Expand Down
85 changes: 37 additions & 48 deletions pkg/proto/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,6 @@ import (
"github.com/wavesplatform/gowaves/pkg/util/common"
)

type TransactionType byte

// All transaction types supported.
const (
GenesisTransaction TransactionType = iota + 1 // 1 - Genesis transaction
PaymentTransaction // 2 - Payment transaction
IssueTransaction // 3 - Issue transaction
TransferTransaction // 4 - Transfer transaction
ReissueTransaction // 5 - Reissue transaction
BurnTransaction // 6 - Burn transaction
ExchangeTransaction // 7 - Exchange transaction
LeaseTransaction // 8 - Lease transaction
LeaseCancelTransaction // 9 - LeaseCancel transaction
CreateAliasTransaction // 10 - CreateAlias transaction
MassTransferTransaction // 11 - MassTransfer transaction
DataTransaction // 12 - Data transaction
SetScriptTransaction // 13 - SetScript transaction
SponsorshipTransaction // 14 - Sponsorship transaction
SetAssetScriptTransaction // 15 - SetAssetScript transaction
InvokeScriptTransaction // 16 - InvokeScript transaction
UpdateAssetInfoTransaction // 17 - UpdateAssetInfoTransaction
EthereumMetamaskTransaction // 18 - EthereumMetamaskTransaction is a transaction which is received from metamask
InvokeExpressionTransaction // 19 - InvokeExpressionTransaction
)

// TxFailureReason indicates Transactions failure reasons.
type TxFailureReason byte

Expand Down Expand Up @@ -71,23 +46,24 @@ const (
createAliasLen = crypto.PublicKeySize + 2 + 8 + 8 + aliasFixedSize

// Max allowed versions of transactions.
MaxUncheckedTransactionVersion = 127
MaxGenesisTransactionVersion = 2
MaxPaymentTransactionVersion = 2
MaxTransferTransactionVersion = 127
MaxIssueTransactionVersion = 127
MaxReissueTransactionVersion = 127
MaxBurnTransactionVersion = 127
MaxExchangeTransactionVersion = 127
MaxLeaseTransactionVersion = 127
MaxLeaseCancelTransactionVersion = 127
MaxCreateAliasTransactionVersion = 127
MaxMassTransferTransactionVersion = 127
MaxDataTransactionVersion = 127
MaxSetScriptTransactionVersion = 127
MaxSponsorshipTransactionVersion = 127
MaxSetAssetScriptTransactionVersion = 127
MaxInvokeScriptTransactionVersion = 127
MaxUpdateAssetInfoTransactionVersion = 127
MaxTransferTransactionVersion = 3
MaxIssueTransactionVersion = 3
MaxReissueTransactionVersion = 3
MaxBurnTransactionVersion = 3
MaxExchangeTransactionVersion = 3
MaxLeaseTransactionVersion = 3
MaxLeaseCancelTransactionVersion = 3
MaxCreateAliasTransactionVersion = 3
MaxMassTransferTransactionVersion = 2
MaxDataTransactionVersion = 2
MaxSetScriptTransactionVersion = 2
MaxSponsorshipTransactionVersion = 2
MaxSetAssetScriptTransactionVersion = 2
MaxInvokeScriptTransactionVersion = 2
MaxUpdateAssetInfoTransactionVersion = 1

MinFee = 100_000
MinFeeScriptedAsset = 400_000
Expand Down Expand Up @@ -181,6 +157,12 @@ func (a TransactionTypeInfo) String() string {
return sb.String()
}

// TransactionValidationParams contains parameters for transaction validation.
type TransactionValidationParams struct {
Scheme Scheme
CheckVersion bool
}

// Transaction is a set of common transaction functions.
type Transaction interface {
// Getters which are common for all transactions.
Expand All @@ -191,6 +173,7 @@ type Transaction interface {
// This is temporary workaround until we have the same struct for both
// Signature and Proofs transactions.
GetTypeInfo() TransactionTypeInfo
GetType() TransactionType
GetVersion() byte
GetID(scheme Scheme) ([]byte, error)
GetSender(scheme Scheme) (Address, error)
Expand All @@ -201,7 +184,7 @@ type Transaction interface {
// Validate checks that all transaction fields are valid.
// This includes ranges checks, and sanity checks specific for each transaction type:
// for example, negative amounts for transfers.
Validate(scheme Scheme) (Transaction, error)
Validate(params TransactionValidationParams) (Transaction, error)

// GenerateID sets transaction ID.
// For most transactions ID is hash of transaction body.
Expand Down Expand Up @@ -467,6 +450,10 @@ func (tx Genesis) GetTypeInfo() TransactionTypeInfo {
return TransactionTypeInfo{tx.Type, Signature}
}

func (tx Genesis) GetType() TransactionType {
return tx.Type
}

func (tx Genesis) GetVersion() byte {
return tx.Version
}
Expand Down Expand Up @@ -532,7 +519,7 @@ func NewUnsignedGenesis(recipient WavesAddress, amount, timestamp uint64) *Genes
}

// Validate checks the validity of transaction parameters and it's signature.
func (tx *Genesis) Validate(scheme Scheme) (Transaction, error) {
func (tx *Genesis) Validate(params TransactionValidationParams) (Transaction, error) {
if tx.Version < 1 || tx.Version > MaxGenesisTransactionVersion {
return tx, errors.Errorf("bad version %d for Genesis transaction", tx.Version)
}
Expand All @@ -542,7 +529,7 @@ func (tx *Genesis) Validate(scheme Scheme) (Transaction, error) {
if !validJVMLong(tx.Amount) {
return tx, errors.New("amount is too big")
}
if ok, err := tx.Recipient.Valid(scheme); !ok {
if ok, err := tx.Recipient.Valid(params.Scheme); !ok {
return tx, errors.Wrapf(err, "invalid recipient address '%s'", tx.Recipient.String())
}
return tx, nil
Expand Down Expand Up @@ -736,6 +723,10 @@ func (tx Payment) GetTypeInfo() TransactionTypeInfo {
return TransactionTypeInfo{tx.Type, Signature}
}

func (tx Payment) GetType() TransactionType {
return tx.Type
}

func (tx Payment) GetVersion() byte {
return tx.Version
}
Expand Down Expand Up @@ -785,7 +776,7 @@ func NewUnsignedPayment(senderPK crypto.PublicKey, recipient WavesAddress, amoun
return &Payment{Type: PaymentTransaction, Version: 1, SenderPK: senderPK, Recipient: recipient, Amount: amount, Fee: fee, Timestamp: timestamp}
}

func (tx *Payment) Validate(_ Scheme) (Transaction, error) {
func (tx *Payment) Validate(_ TransactionValidationParams) (Transaction, error) {
if tx.Version < 1 || tx.Version > MaxPaymentTransactionVersion {
return tx, errors.Errorf("bad version %d for Payment transaction", tx.Version)
}
Expand Down Expand Up @@ -1249,10 +1240,7 @@ func (tr *Transfer) marshalBinary() ([]byte, error) {
p += 8
copy(buf[p:], rb)
p += rl
attBytes, err := att.Bytes()
if err != nil {
return nil, errors.Wrap(err, "failed to marshal Transfer body")
}
attBytes := att.Bytes()
if err := PutBytesWithUInt16Len(buf[p:], attBytes); err != nil {
return nil, errors.Wrap(err, "failed to marshal Transfer body")
}
Expand Down Expand Up @@ -1520,6 +1508,7 @@ func (b *Burn) UnmarshalBinary(data []byte) error {
type Exchange interface {
GetID(scheme Scheme) ([]byte, error)
GetSenderPK() crypto.PublicKey
Verify(scheme Scheme, pk crypto.PublicKey) (bool, error)
GetBuyOrder() (Order, error)
GetSellOrder() (Order, error)
GetOrder1() Order
Expand Down
Loading

0 comments on commit 85fc27e

Please sign in to comment.