snapshot

package
v1.1.0-alpha.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const Version1 = 1

Variables

View Source
var ErrSkip = stderrs.New("skip")

ErrSkip is returned by SectionVisitor.VisitSection to skip a section.

Functions

func CollectAnchors

func CollectAnchors(w *Writer, batch *database.Batch, network config.NetworkUrl) error

CollectAnchors collects anchors from the anchor ledger's anchor sequence chain.

func FullCollect

func FullCollect(batch *database.Batch, file io.WriteSeeker, network config.NetworkUrl, logger log.Logger, preserve bool) error

FullCollect collects a snapshot including additional records required for a fully-functioning node.

func FullRestore

func FullRestore(db database.Beginner, file ioutil2.SectionReader, logger log.Logger, network *config.Describe) error

FullRestore restores the snapshot and rebuilds indices.

func Open

func Open(file ioutil2.SectionReader) (*Header, *Reader, error)

Open reads a snapshot file, returning the header values and a reader.

func Restore

func Restore(db database.Beginner, file ioutil2.SectionReader, logger log.Logger) error

func Visit

func Visit(file ioutil2.SectionReader, visitor interface{}) error

Types

type Account

type Account struct {
	Hash [32]byte
	// Main is the main state of the account.
	Main protocol.Account `json:"main,omitempty" form:"main" query:"main" validate:"required"`
	// OldChains is deprecated. Use Chains instead.
	OldChains []*OldChain `json:"oldChains,omitempty" form:"oldChains" query:"oldChains" validate:"required"`
	// Pending is the state of the account's pending transactions.
	Pending []*url.TxID `json:"pending,omitempty" form:"pending" query:"pending" validate:"required"`
	// Directory lists the account's sub-accounts.
	Directory []*url.URL `json:"directory,omitempty" form:"directory" query:"directory" validate:"required"`
	// Url is the URL of the account.
	Url *url.URL `json:"url,omitempty" form:"url" query:"url" validate:"required"`
	// Chains is the state of the account's chains.
	Chains []*Chain `json:"chains,omitempty" form:"chains" query:"chains" validate:"required"`
	// contains filtered or unexported fields
}

func CollectAccount

func CollectAccount(record *database.Account, fullChainHistory bool) (*Account, error)

func (*Account) ConvertOldChains

func (a *Account) ConvertOldChains(markPower int64)

ConvertOldChains converts OldChains to Chains.

func (*Account) Copy

func (v *Account) Copy() *Account

func (*Account) CopyAsInterface

func (v *Account) CopyAsInterface() interface{}

func (*Account) Equal

func (v *Account) Equal(u *Account) bool

func (*Account) IsValid

func (v *Account) IsValid() error

func (*Account) MarshalBinary

func (v *Account) MarshalBinary() ([]byte, error)

func (*Account) MarshalJSON

func (v *Account) MarshalJSON() ([]byte, error)

func (*Account) Restore

func (a *Account) Restore(batch *database.Batch) error

func (*Account) RestoreChainHead

func (a *Account) RestoreChainHead(batch *database.Batch, c *Chain) (*database.Chain2, error)

func (*Account) UnmarshalBinary

func (v *Account) UnmarshalBinary(data []byte) error

func (*Account) UnmarshalBinaryFrom

func (v *Account) UnmarshalBinaryFrom(rd io.Reader) error

func (*Account) UnmarshalJSON

func (v *Account) UnmarshalJSON(data []byte) error

type AccountVisitor

type AccountVisitor interface{ VisitAccount(*Account, int) error }

type Chain added in v1.1.0

type Chain struct {
	Name       string                  `json:"name,omitempty" form:"name" query:"name" validate:"required"`
	Type       merkle.ChainType        `json:"type,omitempty" form:"type" query:"type" validate:"required"`
	MarkPower  uint64                  `json:"markPower,omitempty" form:"markPower" query:"markPower" validate:"required"`
	Head       *database.MerkleState   `json:"head,omitempty" form:"head" query:"head" validate:"required"`
	MarkPoints []*database.MerkleState `json:"markPoints,omitempty" form:"markPoints" query:"markPoints" validate:"required"`
	// contains filtered or unexported fields
}

func CollectChain added in v1.1.0

func CollectChain(c *database.MerkleManager) (*Chain, error)

func (*Chain) AddEntry added in v1.1.0

func (c *Chain) AddEntry(hash []byte)

AddEntry adds an entry to the snapshot as if it were added to the chain. AddEntry's logic must mirror MerkleManager.AddHash.

func (*Chain) Copy added in v1.1.0

func (v *Chain) Copy() *Chain

func (*Chain) CopyAsInterface added in v1.1.0

func (v *Chain) CopyAsInterface() interface{}

func (*Chain) Equal added in v1.1.0

func (v *Chain) Equal(u *Chain) bool

func (*Chain) IsValid added in v1.1.0

func (v *Chain) IsValid() error

func (*Chain) MarshalBinary added in v1.1.0

func (v *Chain) MarshalBinary() ([]byte, error)

func (*Chain) MarshalJSON added in v1.1.0

func (v *Chain) MarshalJSON() ([]byte, error)

func (*Chain) RestoreElementIndexFromHead added in v1.1.0

func (s *Chain) RestoreElementIndexFromHead(c *database.MerkleManager) error

func (*Chain) RestoreElementIndexFromMarkPoints added in v1.1.0

func (s *Chain) RestoreElementIndexFromMarkPoints(c *database.MerkleManager, start, end int) error

func (*Chain) RestoreHead added in v1.1.0

func (s *Chain) RestoreHead(c *database.MerkleManager) error

func (*Chain) RestoreMarkPointRange added in v1.1.0

func (s *Chain) RestoreMarkPointRange(c *database.MerkleManager, start, end int) error

func (*Chain) RestoreSnapshot added in v1.1.0

func (c *Chain) RestoreSnapshot(s *database.MerkleManager) error

func (*Chain) UnmarshalBinary added in v1.1.0

func (v *Chain) UnmarshalBinary(data []byte) error

func (*Chain) UnmarshalBinaryFrom added in v1.1.0

func (v *Chain) UnmarshalBinaryFrom(rd io.Reader) error

func (*Chain) UnmarshalJSON added in v1.1.0

func (v *Chain) UnmarshalJSON(data []byte) error

type CollectOptions added in v1.1.0

type CollectOptions struct {
	Logger           log.Logger
	VisitAccount     func(acct *Account) error
	VisitTransaction func(txn *Transaction) error
	VisitSignature   func(sig *Signature) error

	// PreserveAccountHistory is called for each account to test if the
	// account's transaction history should be preserved. If
	// PreserveAccountHistory is unspecified, all account history is preserved.
	PreserveAccountHistory func(account *database.Account) (bool, error)
}

type HashSet

type HashSet struct {
	Hashes [][32]byte
	// contains filtered or unexported fields
}

func (*HashSet) Add

func (s *HashSet) Add(h [32]byte)

func (*HashSet) CollectFromChain

func (s *HashSet) CollectFromChain(a *database.Account, c *database.Chain2) error
type Header struct {

	// Version is the snapshot format version.
	Version uint64 `json:"version,omitempty" form:"version" query:"version" validate:"required"`
	// Height is the snapshot's block height.
	Height uint64 `json:"height,omitempty" form:"height" query:"height" validate:"required"`
	// RootHash is the snapshot's root hash.
	RootHash [32]byte `json:"rootHash,omitempty" form:"rootHash" query:"rootHash" validate:"required"`
	// Timestamp is the snapshot's block time.
	Timestamp time.Time `json:"timestamp,omitempty" form:"timestamp" query:"timestamp" validate:"required"`
	// ExecutorVersion is the snapshot's executor version.
	ExecutorVersion protocol.ExecutorVersion `json:"executorVersion,omitempty" form:"executorVersion" query:"executorVersion" validate:"required"`
	// contains filtered or unexported fields
}

func (*Header) Copy

func (v *Header) Copy() *Header

func (*Header) CopyAsInterface

func (v *Header) CopyAsInterface() interface{}

func (*Header) Equal

func (v *Header) Equal(u *Header) bool

func (*Header) IsValid

func (v *Header) IsValid() error

func (*Header) MarshalBinary

func (v *Header) MarshalBinary() ([]byte, error)

func (*Header) MarshalJSON

func (v *Header) MarshalJSON() ([]byte, error)

func (*Header) ReadFrom

func (h *Header) ReadFrom(rd io.Reader) (int64, error)

func (*Header) UnmarshalBinary

func (v *Header) UnmarshalBinary(data []byte) error

func (*Header) UnmarshalBinaryFrom

func (v *Header) UnmarshalBinaryFrom(rd io.Reader) error

func (*Header) UnmarshalJSON

func (v *Header) UnmarshalJSON(data []byte) error

func (*Header) WriteTo

func (h *Header) WriteTo(wr io.Writer) (int64, error)

type HeaderVisitor added in v1.1.0

type HeaderVisitor interface{ VisitHeader(*Header) error }

type OldChain

type OldChain struct {
	Name    string             `json:"name,omitempty" form:"name" query:"name" validate:"required"`
	Type    protocol.ChainType `json:"type,omitempty" form:"type" query:"type" validate:"required"`
	Count   uint64             `json:"count,omitempty" form:"count" query:"count" validate:"required"`
	Pending [][]byte           `json:"pending,omitempty" form:"pending" query:"pending" validate:"required"`
	Entries [][]byte           `json:"entries,omitempty" form:"entries" query:"entries" validate:"required"`
	// contains filtered or unexported fields
}

func (*OldChain) Copy

func (v *OldChain) Copy() *OldChain

func (*OldChain) CopyAsInterface

func (v *OldChain) CopyAsInterface() interface{}

func (*OldChain) Equal

func (v *OldChain) Equal(u *OldChain) bool

func (*OldChain) IsValid

func (v *OldChain) IsValid() error

func (*OldChain) MarshalBinary

func (v *OldChain) MarshalBinary() ([]byte, error)

func (*OldChain) MarshalJSON

func (v *OldChain) MarshalJSON() ([]byte, error)

func (*OldChain) UnmarshalBinary

func (v *OldChain) UnmarshalBinary(data []byte) error

func (*OldChain) UnmarshalBinaryFrom

func (v *OldChain) UnmarshalBinaryFrom(rd io.Reader) error

func (*OldChain) UnmarshalJSON

func (v *OldChain) UnmarshalJSON(data []byte) error

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(file ioutil2.SectionReader) *Reader

func (*Reader) Next

func (r *Reader) Next() (*ReaderSection, error)

Next finds the section.

type ReaderSection

type ReaderSection struct {
	// contains filtered or unexported fields
}

func (*ReaderSection) Offset

func (s *ReaderSection) Offset() int64

func (*ReaderSection) Open

func (*ReaderSection) Size

func (s *ReaderSection) Size() int64

func (*ReaderSection) Type

func (s *ReaderSection) Type() SectionType

type RestoreVisitor

type RestoreVisitor struct {
	DisableWriteBatching bool
	CompressChains       bool
	// contains filtered or unexported fields
}

RestoreVisitor is a visitor that restores accounts, transactions, and signatures.

func NewRestoreVisitor

func NewRestoreVisitor(db database.Beginner, logger log.Logger) *RestoreVisitor

func (*RestoreVisitor) VisitAccount

func (v *RestoreVisitor) VisitAccount(acct *Account, i int) error

func (*RestoreVisitor) VisitHeader added in v1.1.0

func (v *RestoreVisitor) VisitHeader(h *Header) error

func (*RestoreVisitor) VisitSignature

func (v *RestoreVisitor) VisitSignature(sig *Signature, i int) error

func (*RestoreVisitor) VisitTransaction

func (v *RestoreVisitor) VisitTransaction(txn *Transaction, i int) error

type SectionType

type SectionType uint64
const SectionTypeAccounts SectionType = 2

SectionTypeAccounts .

const SectionTypeGzTransactions SectionType = 5

SectionTypeGzTransactions .

const SectionTypeHeader SectionType = 1

SectionTypeHeader .

const SectionTypeSignatures SectionType = 4

SectionTypeSignatures .

const SectionTypeTransactions SectionType = 3

SectionTypeTransactions .

func SectionTypeByName

func SectionTypeByName(name string) (SectionType, bool)

SectionTypeByName returns the named Section Type.

func (SectionType) GetEnumValue

func (v SectionType) GetEnumValue() uint64

GetEnumValue returns the value of the Section Type

func (SectionType) MarshalJSON

func (v SectionType) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Section Type to JSON as a string.

func (*SectionType) SetEnumValue

func (v *SectionType) SetEnumValue(id uint64) bool

SetEnumValue sets the value. SetEnumValue returns false if the value is invalid.

func (SectionType) String

func (v SectionType) String() string

String returns the name of the Section Type.

func (*SectionType) UnmarshalJSON

func (v *SectionType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the Section Type from JSON as a string.

type SectionVisitor

type SectionVisitor interface{ VisitSection(*ReaderSection) error }

type SectionWriter

type SectionWriter struct {
	// contains filtered or unexported fields
}

func (*SectionWriter) Close

func (w *SectionWriter) Close() error

func (*SectionWriter) Seek

func (w *SectionWriter) Seek(offset int64, whence int) (int64, error)

func (*SectionWriter) Write

func (w *SectionWriter) Write(p []byte) (n int, err error)

type Signature

type Signature struct {
	Txid      *url.TxID          `json:"txid,omitempty" form:"txid" query:"txid" validate:"required"`
	Signature protocol.Signature `json:"signature,omitempty" form:"signature" query:"signature" validate:"required"`
	// contains filtered or unexported fields
}

func CollectSignature

func CollectSignature(batch *database.Batch, hash [32]byte) (*Signature, error)

func (*Signature) Copy

func (v *Signature) Copy() *Signature

func (*Signature) CopyAsInterface

func (v *Signature) CopyAsInterface() interface{}

func (*Signature) Equal

func (v *Signature) Equal(u *Signature) bool

func (*Signature) IsValid

func (v *Signature) IsValid() error

func (*Signature) MarshalBinary

func (v *Signature) MarshalBinary() ([]byte, error)

func (*Signature) MarshalJSON

func (v *Signature) MarshalJSON() ([]byte, error)

func (*Signature) Restore

func (s *Signature) Restore(header *Header, batch *database.Batch) error

func (*Signature) UnmarshalBinary

func (v *Signature) UnmarshalBinary(data []byte) error

func (*Signature) UnmarshalBinaryFrom

func (v *Signature) UnmarshalBinaryFrom(rd io.Reader) error

func (*Signature) UnmarshalJSON

func (v *Signature) UnmarshalJSON(data []byte) error

type SignatureVisitor

type SignatureVisitor interface{ VisitSignature(*Signature, int) error }

type Transaction

type Transaction struct {
	Transaction   *protocol.Transaction       `json:"transaction,omitempty" form:"transaction" query:"transaction" validate:"required"`
	Status        *protocol.TransactionStatus `json:"status,omitempty" form:"status" query:"status" validate:"required"`
	SignatureSets []*TxnSigSet                `json:"signatureSets,omitempty" form:"signatureSets" query:"signatureSets" validate:"required"`
	// contains filtered or unexported fields
}

func CollectTransaction

func CollectTransaction(batch *database.Batch, hash [32]byte) (*Transaction, error)

func (*Transaction) Copy

func (v *Transaction) Copy() *Transaction

func (*Transaction) CopyAsInterface

func (v *Transaction) CopyAsInterface() interface{}

func (*Transaction) Equal

func (v *Transaction) Equal(u *Transaction) bool

func (*Transaction) IsValid

func (v *Transaction) IsValid() error

func (*Transaction) MarshalBinary

func (v *Transaction) MarshalBinary() ([]byte, error)

func (*Transaction) MarshalJSON

func (v *Transaction) MarshalJSON() ([]byte, error)

func (*Transaction) Restore

func (t *Transaction) Restore(header *Header, batch *database.Batch) error

func (*Transaction) UnmarshalBinary

func (v *Transaction) UnmarshalBinary(data []byte) error

func (*Transaction) UnmarshalBinaryFrom

func (v *Transaction) UnmarshalBinaryFrom(rd io.Reader) error

func (*Transaction) UnmarshalJSON

func (v *Transaction) UnmarshalJSON(data []byte) error

type TransactionVisitor

type TransactionVisitor interface{ VisitTransaction(*Transaction, int) error }

type TxnSigSet

type TxnSigSet struct {
	Signer  *url.URL               `json:"signer,omitempty" form:"signer" query:"signer" validate:"required"`
	Version uint64                 `json:"version,omitempty" form:"version" query:"version" validate:"required"`
	Entries []database.SigSetEntry `json:"entries,omitempty" form:"entries" query:"entries" validate:"required"`
	// contains filtered or unexported fields
}

func (*TxnSigSet) Copy

func (v *TxnSigSet) Copy() *TxnSigSet

func (*TxnSigSet) CopyAsInterface

func (v *TxnSigSet) CopyAsInterface() interface{}

func (*TxnSigSet) Equal

func (v *TxnSigSet) Equal(u *TxnSigSet) bool

func (*TxnSigSet) IsValid

func (v *TxnSigSet) IsValid() error

func (*TxnSigSet) MarshalBinary

func (v *TxnSigSet) MarshalBinary() ([]byte, error)

func (*TxnSigSet) MarshalJSON

func (v *TxnSigSet) MarshalJSON() ([]byte, error)

func (*TxnSigSet) UnmarshalBinary

func (v *TxnSigSet) UnmarshalBinary(data []byte) error

func (*TxnSigSet) UnmarshalBinaryFrom

func (v *TxnSigSet) UnmarshalBinaryFrom(rd io.Reader) error

func (*TxnSigSet) UnmarshalJSON

func (v *TxnSigSet) UnmarshalJSON(data []byte) error

type Writer

type Writer struct {
	Logger logging.OptionalLogger
	// contains filtered or unexported fields
}

func Collect

func Collect(batch *database.Batch, header *Header, file io.WriteSeeker, opts CollectOptions) (*Writer, error)

func Create

func Create(file io.WriteSeeker, header *Header) (*Writer, error)

func NewWriter

func NewWriter(w io.WriteSeeker) *Writer

func (*Writer) CollectAccounts

func (w *Writer) CollectAccounts(batch *database.Batch, opts CollectOptions) error

func (*Writer) CollectSignatures

func (w *Writer) CollectSignatures(batch *database.Batch, hashes [][32]byte, opts CollectOptions) error

func (*Writer) CollectTransactions

func (w *Writer) CollectTransactions(batch *database.Batch, hashes [][32]byte, opts CollectOptions) error

func (*Writer) Open

func (w *Writer) Open(typ SectionType) (*SectionWriter, error)

Open opens a section.

func (*Writer) WriteTransactions

func (w *Writer) WriteTransactions(txns []*Transaction, gz bool) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL