Select Git revision
snapshot.go
Luca Moser
authored and
GitHub
committed
* Feat: initial commit * Feat: added setPreferred to TransactionMetadata * Feat: added a Conflicting() method to the transactionMetadata * Fix: fixed logic bug * Feat: refactored fcob * Refactor: refactored additional code * Fix: fixed a bug in ForeachConsumers * Refactor: cleaned up code * Feat: implemented FCOB consensus into the valuetransfer dapp * Refactor: refactored FCOB * Docs: added some additional comments * Docs: fixed comments * add branch manager conflict test * cleans failing test * Refactor: commit before branch change * Fix: fixed bug in AggregateBranches * assert aggr. branch IDs * expands branch conflict detection test * add visualisation of branch graph of test * Feat: added PayloadLiked Event * Refactor: fixed some missing comments + added liked to marshal * Feat: reworked the preferred and liked propagation * Refactor: cleaned up some logic * Refactor: simplified code * Refactor: cleaned up more stuff :P * Refactor: refactor * Feat: moved test + refactored fcob * adds more tests * fixes liked state not getting updated correctly of conflict members * adds additional liked/preferred propagation test * Fix: fixed missing preferred propagation to aggregated branches * Fix: fixed a few bugs in liked propagation * adapt to new hive.go version * upgrade hive.go * Feat: started implementing a wallet * Feat: extended wallet files * remove weird test * use mem db for tests * more tests * use store backed sequence * add option to use in-memory database * address review comments * First tests for individual components of AttachPayloadSync * Fix: fixed missing events in branchmanaer * Feat: propagate changes from branch to transaction * Add tests for checkTransactionOutputs * Feat: started implementing confirmed propagation * Fix: fixed unreachable code * Add more tests * Refactor: refactored some code according to wolfgangs review * Refactor: cleaned up the code according to DRY * Refactor: refactored according to wollac * Refactor: refactored according to wollac * Refactor: refactored according to wollac * Refactor: refactored the code to make it more readable * Refactor: added some doc comments + cleaned up some more code *adds orderedMap unit tests * Fix linter warnings * test: Add queue unit tests * Add more tests * Adjust imports order * WIP more tests * Add TestBookTransaction * Update TestBookTransaction * Add more tests * WIP tests * Add TestCalculateBranchOfTransaction * Add TestMoveTransactionToBranch * Add TestFork * Add TestBookPayload * Add test for checkPayloadSolidity * Add TestSetTransactionPreferred * Add more tests * Fix Tangle test * Feat: started implementing lucas test cases * Feat: fixed some issued + further tests * Feat: started adding invalid txs check * Feat: added removal logic for invalid transactions * Refactor: removed Println * Add test for 2nd Reattachment * feat: Add first value transfer integration test * fix: fix wrong plugin name * Add aggregated branches test cases * Feat: added a method to generate AggregatedBranchIDs * Use GenerateAggregatedBranchID in test * Feat: refactored delete logic * Fix: fixed broken test * Feat: added final test cases for invalid txs / payloads * WIP * Value tangle concurrency tests (#451) * Add simple concurrency test * Add reverse and concurrent transaction and value object solidification tests and fix bug when value object was visited more than once * Add some documentation to make tests easily understandable * WIP propagation tests but fixed already couple of bugs * Fix: fixed some bugs * Feat: added propagation to inclusion states to tx and its outputs * Feat: finished the propagation down to the tx and its outputs * WIP propagation tests and fix bugs * Add colored tokens test * Add value tangle test to github workflow * fix: Fix wrong function name in comments * refactor: Make testSnapshots disabled in default and minor tweaks * Feat: fixed some issues and introduced a Debugger * Refactor: added a few comments * Split massive test file into slightly more digestible chunks * Clean up propagation tests * Feat: fixed bugs * Feat: enabled missing tests * Add some documentation and missing checks for aggregated branches * Clean up tangle tests * adds snapshot type * Fix: finalized wasn't propagated when a branch was rejected * implements ReadFrom and WriteTo for Snapshot * read in snapshot file if snapshot path is defined * renames snapshot test file * WIP debugging concurrency bug of death * Feat: added more reliable fails in test case * Fix: fixes a race condition in solidification * Clean up test * adds assets volume to integration test containers * fixes some asserts * adds non-working conflict integration test * check transaction availability in partition * renames integration test * lower amount of peers * first passing version of consensus integration test * remove debug printlns * do all integration tests again * increases avg. network delay fcob rule, removes debug printlns * go mod tidy by Marie Kondō * renames incl. state. conflict to conflicting * go fmt tangle.go * go fmt tangle_test, goimports dapp.go * goimports again because the dog is sad * run consensus integration test on the CI * use explicit pumba version 0.7.2 * pray to the CI gods for the test to pass * fix panic when tangle.Fork() is called * readd all tests again * reset integration framework paras * removes test snapshot plugin * get rid of test snapshot plugin * fixes wrong use of Println * removes random tool * removes duplicated value entry in GH CI workflows * xxx * wip * fixes integration test Co-authored-by: Hans Moog <hm@mkjc.net> Co-authored-by:
Wolfgang Welz <welzwo@gmail.com> Co-authored-by:
jonastheis <mail@jonastheis.de> Co-authored-by:
capossele <angelocapossele@gmail.com> Co-authored-by:
jkrvivian <jkrvivian@gmail.com>
snapshot.go 4.45 KiB
package tangle
import (
"encoding/binary"
"fmt"
"io"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
)
// Snapshot defines a snapshot of the ledger state.
type Snapshot map[transaction.ID]map[address.Address][]*balance.Balance
// WriteTo writes the snapshot data to the given writer in the following format:
// transaction_count(int64)
// -> transaction_count * transaction_id(32byte)
// ->address_count(int64)
// ->address_count * address(33byte)
// ->balance_count(int64)
// ->balance_count * value(int64)+color(32byte)
func (s Snapshot) WriteTo(writer io.Writer) (int64, error) {
var bytesWritten int64
transactionCount := len(s)
if err := binary.Write(writer, binary.LittleEndian, int64(transactionCount)); err != nil {
return 0, fmt.Errorf("unable to write transactions count: %w", err)
}
bytesWritten += 8
for txID, addresses := range s {
if err := binary.Write(writer, binary.LittleEndian, txID); err != nil {
return bytesWritten, fmt.Errorf("unable to write transaction ID: %w", err)
}
bytesWritten += transaction.IDLength
if err := binary.Write(writer, binary.LittleEndian, int64(len(addresses))); err != nil {
return bytesWritten, fmt.Errorf("unable to write address count: %w", err)
}
bytesWritten += 8
for addr, balances := range addresses {
if err := binary.Write(writer, binary.LittleEndian, addr); err != nil {
return bytesWritten, fmt.Errorf("unable to write address: %w", err)
}
bytesWritten += address.Length
if err := binary.Write(writer, binary.LittleEndian, int64(len(balances))); err != nil {
return bytesWritten, fmt.Errorf("unable to write balance count: %w", err)
}
bytesWritten += 8
for _, bal := range balances {
if err := binary.Write(writer, binary.LittleEndian, bal.Value); err != nil {
return bytesWritten, fmt.Errorf("unable to write balance value: %w", err)
}
bytesWritten += 8
if err := binary.Write(writer, binary.LittleEndian, bal.Color); err != nil {
return bytesWritten, fmt.Errorf("unable to write balance color: %w", err)
}
bytesWritten += balance.ColorLength
}
}
}
return bytesWritten, nil
}
// ReadFrom reads the snapshot bytes from the given reader.
// This function overrides existing content of the snapshot.
func (s Snapshot) ReadFrom(reader io.Reader) (int64, error) {
var bytesRead int64
var transactionCount int64
if err := binary.Read(reader, binary.LittleEndian, &transactionCount); err != nil {
return 0, fmt.Errorf("unable to read transaction count: %w", err)
}
bytesRead += 8
var i int64
for ; i < transactionCount; i++ {
txIDBytes := make([]byte, transaction.IDLength)
if err := binary.Read(reader, binary.LittleEndian, txIDBytes); err != nil {
return bytesRead, fmt.Errorf("unable to read transaction ID: %w", err)
}
bytesRead += transaction.IDLength
var addrCount int64
if err := binary.Read(reader, binary.LittleEndian, &addrCount); err != nil {
return bytesRead, fmt.Errorf("unable to read address count: %w", err)
}
bytesRead += 8
txAddrMap := make(map[address.Address][]*balance.Balance, addrCount)
var j int64
for ; j < addrCount; j++ {
addrBytes := make([]byte, address.Length)
if err := binary.Read(reader, binary.LittleEndian, addrBytes); err != nil {
return bytesRead, fmt.Errorf("unable to read address: %w", err)
}
bytesRead += address.Length
var balanceCount int64
if err := binary.Read(reader, binary.LittleEndian, &balanceCount); err != nil {
return bytesRead, fmt.Errorf("unable to read balance count: %w", err)
}
bytesRead += 8
balances := make([]*balance.Balance, balanceCount)
var k int64
for ; k < balanceCount; k++ {
var value int64
if err := binary.Read(reader, binary.LittleEndian, &value); err != nil {
return bytesRead, fmt.Errorf("unable to read balance value: %w", err)
}
bytesRead += 8
color := balance.Color{}
if err := binary.Read(reader, binary.LittleEndian, &color); err != nil {
return bytesRead, fmt.Errorf("unable to read balance color: %w", err)
}
bytesRead += balance.ColorLength
balances[k] = &balance.Balance{Value: value, Color: color}
}
addr := address.Address{}
copy(addr[:], addrBytes)
txAddrMap[addr] = balances
}
txID := transaction.ID{}
copy(txID[:], txIDBytes)
s[txID] = txAddrMap
}
return bytesRead, nil
}