Skip to content

Commit

Permalink
Transaction snapshots (#1065)
Browse files Browse the repository at this point in the history
* Added types

* Renamed a file

* Changed asset- and waves balances structures

* Commented a function

* Changed addresses types

* Changed balanceAsset

* Added a constructor

* Added decimals to asset snapshot

* Changed uint8 to int8

* Added a field for asset reissuability

* Changed the type of total quantity

* removed the pointer

* Changed the type of orderID

* Make 'SnapshotManager' as an interface type.

* Replace 'proto.assetID' to 'crypto.Digest'.

* Replace 'proto.Address' to 'proto.WavesAddress'.

* Changed leaseID type

* changed types of leaseIn and leaseOut

* Removed the pointer types from AliasSnapshot

* Change a bit 'AtomicSnapshot' interface.

* Update snapshot types.

* Removed unnecessary fields in 'AccountScriptSnapshot' struct.

* Remove unnecessary types.

* Change 'StaticAssetInfoSnapshot.Issuer' field to 'StaticAssetInfoSnapshot.IssuerPublicKey'.

* Rename 'AssetReissuabilitySnapshot' to 'AssetVolumeSnapshot'.

* Add feature block reward distribution (#1082)

* add feature BlockRewardDistribution

* fix tests

* Improvement of the test on reward distribution to check that remainder of division goes to miner.

* refactor after rewiev

* fix feature info and add reward addresses in testnet and stagenet configs

* DAO and buyback addresses added for MainNet.
Formatting of settings files fixed.

---------

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

* change actions count with feature BlockRewardDistribution activated (#1088)

* change count actions with feature BlockRewardDistribution activated

* fix comment in script

* Merge fix.

* Fix version in comment

* Eth transaction refactoring and tests

---------

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

* Ride add rewards to block info (#1096)

* add feature BlockRewardDistribution

* fix tests

* Improvement of the test on reward distribution to check that remainder of division goes to miner.

* refactor after rewiev

* fix feature info and add reward addresses in testnet and stagenet configs

* change count actions with feature BlockRewardDistribution activated

* Ride version 7 added. Extended version of BlockInfo ride object added.
Ride types representation in objects stdlib description changed to simple string. Parsing of types added to code generation and updated in compiler.
Code generation updated to support Tuple types.

* Fixed code generation for RideV7. Fixed compilation of V7 scripts.
Added rewards structure and function to SmartState to get the block rewards.
Added test on script accessing new rewards field on BlockInfo.

* Fixed FunctionCall usage in tests

* Fixed sorting of rewards with stable sort.

* Script activation check added for RideV7.

* Code improvements

* Restored recursive check of list types in generated code.

* Generation of simplified code for tuple type checks.

* Duplicated tests removed

* Fixed lib version check in Ride compiler

---------

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

* Fix clear-text logging of sensitive information. (#1128)

* Bump golang.org/x/sync from 0.2.0 to 0.3.0 (#1129)

Bumps [golang.org/x/sync](https://github.com/golang/sync) from 0.2.0 to 0.3.0.
- [Commits](golang/sync@v0.2.0...v0.3.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sync
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alexey Kiselev <[email protected]>

* Added 'LeaseStateStatus'. Changed types in 'LeaseStateSnapshot'.

* Rename 'LeaseStateStatus.Status' to 'LeaseStateStatus.Value'.

* Add methods to 'SnapshotManager' interface. Changed 'AtomicSnapshot' interface.

* Snapshot applier (#1145)

* Create marshal/unmarshal methods for 'leasing' structure in 'pkg/state'.

* WIP: rollbackable map.

* Return 'balanceProfile' and 'wavesBalanceRecord' by value.

* Started 'snapshotApplier.'

* Add apply methods for assets snapshot applying.

* Add 'snapshotApplier.applySponsorship' method.

* Add 'snapshotApplier.applyAccountScript' method.

* Refactor 'ordersVolumes'.

* Add 'snapshotApplier.applyFilledVolumeAndFee' method.

* Add 'snapshotApplier.applyDataEntry' method.

* Add 'snapshotApplier.applyLeaseState' method.

* Revert "WIP: rollbackable map."

This reverts commit cb34969.

* Created and used 'SnapshotApplierInfo' interface in 'state' package.

* Create 'SnapshotApplier' interface in 'state' package.

* Refactor 'SnapshotApplier' interface.

* Remove 'SnapshotApplierInfo' interface.

* Extracted 'snapshotApplierStorages'.

* Rename 'ApplyDataEntry' to 'ApplyDataEntries'.

* Replace 'SnapshotManager' to 'SnapshotApplier'.

* Node transaction snapshots (#1078)

* Added a conversion function

* Added payment transaction conversion

* Added transfer tx conversion

* Transfer tx conversion changed

* Added issue and reissue tx conversions

* Issue

* Issue, reissue, burn, exchange

* Hanled lease transactions

* Finished performers

* Added snapshots for all types of transactions

* Fixed types after merging

* Fixed issue snapshot mistake

* Added rewards snapshot in append block

* Changed functions to newest

* Added snapshots from actions

* Removed todos

* Deleted useless code

* Fixed a mistake with leasing cancel

* Added tests for issue and reissue transactions

* Fixed tests

* fixed implicit memory aliasing

* Added tests for burn, lease, lease cancel, exchange and create alias transactions

* Added tests for data, sponsorship, set account and asset script transactions

* Added a test for the invoke transaction snapshots

* Fixed after merge

* Fixed a function

* Moved snapshot generation

* Remove 'SnapshotManager' interface.

* Added a todo

* Refactored perfomerInfo

* Refactored performer info again

* Moved generation to snapshot generator

* Fixed some linter issues

* Added an asset atomic snapshot for issue transaction

* Replaced current recording to storage to snapshot applier (#1162)

* Replaced current recording to storage to snapshot applier

* Replaced to snapshot applier, except balances

* Fixed a comment

* Removed the comment

* Removed unnecessary code

* Returned the linter command back

* Revert "Replaced current recording to storage to snapshot applier (#1162)" (#1164)

This reverts commit 51904b2.

* * Commented invoke snapshots, import ok (#1165)

* Replaced current recording to storage to snapshot applier

* Replaced to snapshot applier, except balances

* Fixed a comment

* Removed the comment

* Removed unnecessary code

* Returned the linter command back

* Added asset script atomic snapshot to the issue script actions

* Fixed some linter issues

* Fixed a few more linter issues

* Fixed all linter issues

* Fixed err shadowing

* Fixed a mistake with issue counter

* removed a useless line

* Fixed applying order transactions

* Fixed applying order transactions

* Added lising snapshot to the tx diff generated group

* Moved complexity saving into transaction performer

* Moved complexity saving into transaction performer

* removed a line

* Fixed a bug with an empty sender

* Used error.Is

* Set an empty script for issue with sig

* move snapshots types to proto

* Fixed a bug with wrong action sender

* Fixed a bug with wrong action sender

* Add 'TransactionStatusSnapshot'.

* Implemented 'AtomicSnapshot' interface for 'TransactionStatusSnapshot'.

* Changed 'AssetScriptSnapshot' and 'scriptStorageState.setAssetScript'.

Removed 'pk' arg from 'setAssetScript'.
Removed two fields from 'AssetScriptSnapshot':
- 'SenderPK'
- 'Complexity'

* * Commented invoke snapshots, import ok

* moved setting complexity and set script to snapshot applier

* Fixed a test and a mistake

* Fixed renaming

* Fixed a comment

* Moved dapp complexity to applier

* Added dapp complexity to set script as well

* Fixed a check mistake

* Fixed a test

* removed empty script check

* removed a todo

* Removed useless code

* Modified a test

* Fixed same keys issue for data entry actions

* Remove invoke snapshot (#1235)

* moved complexity back

* Reverted some changes, import ok

* Returned account script and asset script txs, import ?

* Uncommented internal snapshot, import ok

* Fixed height problem with issue action and issue tx, import NO

* Issue action reverted

* Added log and issueCounter for issue action

* Commented invoke snapshots, import ok

---------

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

---------

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

* Added asset script special snapshot

* Added internal snapshot for script for issue tx

* Separated internal tx snapshots.

* Reduced 'internalSnapshot' interface, removed unnecessary code.

* Fixed improper usages of 'balances.wavesBalance': replaced by 'balances.newestWavesBalance'.

* Added invoke to snapshots, import ok, merged changes (#1236)

* Removed unnecessary 'assetFoundInMap' function.

* Changed 'LeaseStateSnapshot' according to the NODE-2626.

Add new internal snapshots:
- 'InternalLeaseStateActiveInfoSnapshot'
- 'InternalLeaseStateCancelInfoSnapshot'

* Use script from record in 'generateSnapshotsFromAssetsScriptsUncertain'.

* Removed unnecessary condition in 'blockSnapshotsApplier.ApplyAssetScript'.

* Removed unnecessary conditions in 'blockSnapshotsApplier.ApplyAccountScript'.

* Fixed bug with saved current ride estimator version in 'blockSnapshotsApplier.ApplyAccountScript'.

* Added invoke complexity update to internal snapshots

* Fixed PR issues

* Bump state version constant.

* Fixed new PR issues

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Nikolay Eskov <[email protected]>
Co-authored-by: Anton Ilin <[email protected]>
Co-authored-by: Alexey Kiselev <[email protected]>
Co-authored-by: Anton Ilin <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
6 people authored Nov 15, 2023
1 parent c2fd4c2 commit ed3c5f7
Show file tree
Hide file tree
Showing 37 changed files with 3,717 additions and 901 deletions.
212 changes: 212 additions & 0 deletions pkg/proto/snapshot_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
package proto

import (
"math/big"

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

type AtomicSnapshot interface {
Apply(SnapshotApplier) error
/* TODO remove it. It is temporarily used to mark snapshots generated by tx diff that shouldn't be applied,
because balances diffs are applied later in the block. */
IsGeneratedByTxDiff() bool
}

type WavesBalanceSnapshot struct {
Address WavesAddress
Balance uint64
}

func (s WavesBalanceSnapshot) IsGeneratedByTxDiff() bool {
return true
}

func (s WavesBalanceSnapshot) Apply(a SnapshotApplier) error { return a.ApplyWavesBalance(s) }

type AssetBalanceSnapshot struct {
Address WavesAddress
AssetID crypto.Digest
Balance uint64
}

func (s AssetBalanceSnapshot) IsGeneratedByTxDiff() bool {
return true
}

func (s AssetBalanceSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAssetBalance(s) }

type DataEntriesSnapshot struct { // AccountData in pb
Address WavesAddress
DataEntries []DataEntry
}

func (s DataEntriesSnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s DataEntriesSnapshot) Apply(a SnapshotApplier) error { return a.ApplyDataEntries(s) }

type AccountScriptSnapshot struct {
SenderPublicKey crypto.PublicKey
Script Script
VerifierComplexity uint64
}

func (s AccountScriptSnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s AccountScriptSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAccountScript(s) }

type AssetScriptSnapshot struct {
AssetID crypto.Digest
Script Script
}

func (s AssetScriptSnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s AssetScriptSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAssetScript(s) }

type LeaseBalanceSnapshot struct {
Address WavesAddress
LeaseIn uint64
LeaseOut uint64
}

func (s LeaseBalanceSnapshot) IsGeneratedByTxDiff() bool {
return true
}

func (s LeaseBalanceSnapshot) Apply(a SnapshotApplier) error { return a.ApplyLeaseBalance(s) }

type LeaseStateStatus interface{ leaseStateStatusMarker() }

type LeaseStateStatusActive struct {
Amount uint64
Sender WavesAddress
Recipient WavesAddress
}

func (*LeaseStateStatusActive) leaseStateStatusMarker() {}

type LeaseStatusCancelled struct{}

func (*LeaseStatusCancelled) leaseStateStatusMarker() {}

type LeaseStateSnapshot struct {
LeaseID crypto.Digest
Status LeaseStateStatus
}

func (s LeaseStateSnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s LeaseStateSnapshot) Apply(a SnapshotApplier) error { return a.ApplyLeaseState(s) }

type SponsorshipSnapshot struct {
AssetID crypto.Digest
MinSponsoredFee uint64
}

func (s SponsorshipSnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s SponsorshipSnapshot) Apply(a SnapshotApplier) error { return a.ApplySponsorship(s) }

type AliasSnapshot struct {
Address WavesAddress
Alias Alias
}

func (s AliasSnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s AliasSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAlias(s) }

// FilledVolumeFeeSnapshot Filled Volume and Fee.
type FilledVolumeFeeSnapshot struct { // OrderFill
OrderID crypto.Digest
FilledVolume uint64
FilledFee uint64
}

func (s FilledVolumeFeeSnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s FilledVolumeFeeSnapshot) Apply(a SnapshotApplier) error { return a.ApplyFilledVolumeAndFee(s) }

type StaticAssetInfoSnapshot struct {
AssetID crypto.Digest
SourceTransactionID crypto.Digest
IssuerPublicKey crypto.PublicKey
Decimals uint8
IsNFT bool
}

func (s StaticAssetInfoSnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s StaticAssetInfoSnapshot) Apply(a SnapshotApplier) error { return a.ApplyStaticAssetInfo(s) }

type AssetVolumeSnapshot struct { // AssetVolume in pb
AssetID crypto.Digest
TotalQuantity big.Int // volume in protobuf
IsReissuable bool
}

func (s AssetVolumeSnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s AssetVolumeSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAssetVolume(s) }

type AssetDescriptionSnapshot struct { // AssetNameAndDescription in pb
AssetID crypto.Digest
AssetName string
AssetDescription string
ChangeHeight Height // last_updated in pb
}

func (s AssetDescriptionSnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s AssetDescriptionSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAssetDescription(s) }

type TransactionStatusSnapshot struct {
TransactionID crypto.Digest
Status TransactionStatus
}

func (s TransactionStatusSnapshot) Apply(a SnapshotApplier) error {
return a.ApplyTransactionsStatus(s)
}

func (s TransactionStatusSnapshot) IsGeneratedByTxDiff() bool {
return false
}

type SnapshotApplier interface {
ApplyWavesBalance(snapshot WavesBalanceSnapshot) error
ApplyLeaseBalance(snapshot LeaseBalanceSnapshot) error
ApplyAssetBalance(snapshot AssetBalanceSnapshot) error
ApplyAlias(snapshot AliasSnapshot) error
ApplyStaticAssetInfo(snapshot StaticAssetInfoSnapshot) error
ApplyAssetDescription(snapshot AssetDescriptionSnapshot) error
ApplyAssetVolume(snapshot AssetVolumeSnapshot) error
ApplyAssetScript(snapshot AssetScriptSnapshot) error
ApplySponsorship(snapshot SponsorshipSnapshot) error
ApplyAccountScript(snapshot AccountScriptSnapshot) error
ApplyFilledVolumeAndFee(snapshot FilledVolumeFeeSnapshot) error
ApplyDataEntries(snapshot DataEntriesSnapshot) error
ApplyLeaseState(snapshot LeaseStateSnapshot) error
ApplyTransactionsStatus(snapshot TransactionStatusSnapshot) error
}
8 changes: 8 additions & 0 deletions pkg/proto/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4287,3 +4287,11 @@ func (s StateHashDebug) GetStateHash() *StateHash {
}
return sh
}

type TransactionStatus byte

const (
TransactionSucceeded TransactionStatus = iota
TransactionFailed
TransactionElided
)
Loading

0 comments on commit ed3c5f7

Please sign in to comment.