store

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: Apache-2.0 Imports: 19 Imported by: 6

Documentation

Overview

Copyright 2019-2020 vChain, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2019-2020 vChain, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2019-2020 vChain, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2019-2020 vChain, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const DefaultCompressionFormat = appendable.DefaultCompressionFormat
View Source
const DefaultCompressionLevel = appendable.DefaultCompressionLevel
View Source
const DefaultFileMode = os.FileMode(0755)
View Source
const DefaultFileSize = multiapp.DefaultFileSize
View Source
const DefaultMaxConcurrency = 30
View Source
const DefaultMaxIOConcurrency = 1
View Source
const DefaultMaxKeyLen = 256
View Source
const DefaultMaxLinearProofLen = 1 << 10
View Source
const DefaultMaxTxEntries = 1 << 10 // 1024
View Source
const DefaultMaxValueLen = 4096 // 4Kb
View Source
const MaxFileSize = 1 << 50 // 1 Pb
View Source
const MaxKeyLen = 1024 // assumed to be not lower than hash size
View Source
const MaxParallelIO = 127
View Source
const Version = 1

Variables

View Source
var ErrAlreadyClosed = errors.New("already closed")
View Source
var ErrCorruptedAHtree = errors.New("appendable hash tree is corrupted")
View Source
var ErrCorruptedCLog = errors.New("commit log is corrupted")
View Source
var ErrCorruptedData = errors.New("data is corrupted")
View Source
var ErrDuplicatedKey = errors.New("duplicated key")
View Source
var ErrIllegalArguments = errors.New("illegal arguments")
View Source
var ErrKeyNotFound = tbtree.ErrKeyNotFound
View Source
var ErrLinearProofMaxLenExceeded = errors.New("max linear proof length limit exceeded")
View Source
var ErrMaxConcurrencyLimitExceeded = errors.New("max concurrency limit exceeded")
View Source
var ErrNoMoreEntries = errors.New("no more entries")
View Source
var ErrNullKey = errors.New("null key")
View Source
var ErrSourceTxNewerThanTargetTx = errors.New("source tx is newer than target tx")
View Source
var ErrTxNotFound = errors.New("tx not found")
View Source
var ErrTxSizeGreaterThanMaxTxSize = errors.New("tx size greater than max tx size")
View Source
var ErrUnexpectedLinkingError = errors.New("Internal inconsistency between linear and binary linking")
View Source
var ErrorCorruptedTxData = errors.New("tx data is corrupted")
View Source
var ErrorMaxKeyLenExceeded = errors.New("max key length exceeded")
View Source
var ErrorMaxTxEntriesLimitExceeded = errors.New("max number of entries per tx exceeded")
View Source
var ErrorMaxValueLenExceeded = errors.New("max value length exceeded")
View Source
var ErrorNoEntriesProvided = errors.New("no entries provided")
View Source
var ErrorPathIsNotADirectory = errors.New("path is not a directory")

Functions

func VerifyDualProof

func VerifyDualProof(proof *DualProof, sourceTxID, targetTxID uint64, sourceAlh, targetAlh [sha256.Size]byte) bool

func VerifyInclusion added in v0.9.0

func VerifyInclusion(proof *htree.InclusionProof, kv *KV, root [sha256.Size]byte) bool

func VerifyLinearProof

func VerifyLinearProof(proof *LinearProof, sourceTxID, targetTxID uint64, sourceAlh, targetAlh [sha256.Size]byte) bool

Types

type DualProof

type DualProof struct {
	SourceTxMetadata   *TxMetadata
	TargetTxMetadata   *TxMetadata
	InclusionProof     [][sha256.Size]byte
	ConsistencyProof   [][sha256.Size]byte
	TargetBlTxAlh      [sha256.Size]byte
	LastInclusionProof [][sha256.Size]byte
	LinearProof        *LinearProof
}

type ImmuStore

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

func Open

func Open(path string, opts *Options) (*ImmuStore, error)

func OpenWith

func OpenWith(path string, vLogs []appendable.Appendable, txLog, cLog appendable.Appendable, opts *Options) (*ImmuStore, error)

func (*ImmuStore) Alh

func (s *ImmuStore) Alh() (uint64, [sha256.Size]byte)

func (*ImmuStore) BlInfo

func (s *ImmuStore) BlInfo() (uint64, error)

func (*ImmuStore) Close

func (s *ImmuStore) Close() error

func (*ImmuStore) Commit

func (s *ImmuStore) Commit(entries []*KV) (*TxMetadata, error)

func (*ImmuStore) DualProof

func (s *ImmuStore) DualProof(sourceTx, targetTx *Tx) (proof *DualProof, err error)

DualProof combines linear cryptographic linking i.e. transactions include the linear accumulative hash up to the previous one, with binary cryptographic linking generated by appending the linear accumulative hash values into an incremental hash tree, whose root is also included as part of each transaction and thus considered when calculating the linear accumulative hash. The objective of this proof is the same as the linear proof, that is, generate data for the calculation of the accumulative hash value of the target transaction from the linear accumulative hash value up to source transaction.

func (*ImmuStore) Get added in v0.9.0

func (s *ImmuStore) Get(key []byte) (value []byte, tx uint64, err error)

func (*ImmuStore) GetTs added in v0.9.0

func (s *ImmuStore) GetTs(key []byte, limit int64) (txs []uint64, err error)

func (*ImmuStore) IndexInfo

func (s *ImmuStore) IndexInfo() (uint64, error)

func (*ImmuStore) LinearProof

func (s *ImmuStore) LinearProof(sourceTxID, targetTxID uint64) (*LinearProof, error)

LinearProof returns a list of hashes to calculate Alh@targetTxID from Alh@sourceTxID

func (*ImmuStore) MaxConcurrency

func (s *ImmuStore) MaxConcurrency() int

func (*ImmuStore) MaxIOConcurrency

func (s *ImmuStore) MaxIOConcurrency() int

func (*ImmuStore) MaxKeyLen

func (s *ImmuStore) MaxKeyLen() int

func (*ImmuStore) MaxLinearProofLen

func (s *ImmuStore) MaxLinearProofLen() int

func (*ImmuStore) MaxTxEntries

func (s *ImmuStore) MaxTxEntries() int

func (*ImmuStore) MaxValueLen

func (s *ImmuStore) MaxValueLen() int

func (*ImmuStore) NewReader added in v0.9.0

func (st *ImmuStore) NewReader(snap *tbtree.Snapshot, spec *tbtree.ReaderSpec) (*Reader, error)

NewReader ...

func (*ImmuStore) NewTx

func (s *ImmuStore) NewTx() *Tx

func (*ImmuStore) NewTxReader

func (s *ImmuStore) NewTxReader(txID uint64, tx *Tx, bufSize int) (*TxReader, error)

func (*ImmuStore) ReadOnly

func (s *ImmuStore) ReadOnly() bool

func (*ImmuStore) ReadTx

func (s *ImmuStore) ReadTx(txID uint64, tx *Tx) error

func (*ImmuStore) ReadValue

func (s *ImmuStore) ReadValue(tx *Tx, key []byte) ([]byte, error)

func (*ImmuStore) ReadValueAt

func (s *ImmuStore) ReadValueAt(b []byte, off int64, hvalue [sha256.Size]byte) (int, error)

func (*ImmuStore) SetBlErr

func (s *ImmuStore) SetBlErr(err error)

func (*ImmuStore) Snapshot

func (s *ImmuStore) Snapshot() (*tbtree.Snapshot, error)

func (*ImmuStore) SnapshotSince added in v0.9.0

func (s *ImmuStore) SnapshotSince(tx uint64) (*tbtree.Snapshot, error)

func (*ImmuStore) Sync

func (s *ImmuStore) Sync() error

func (*ImmuStore) Synced

func (s *ImmuStore) Synced() bool

func (*ImmuStore) TxCount

func (s *ImmuStore) TxCount() uint64

type IndexOptions

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

func DefaultIndexOptions

func DefaultIndexOptions() *IndexOptions

func (*IndexOptions) WithCacheSize

func (opts *IndexOptions) WithCacheSize(cacheSize int) *IndexOptions

func (*IndexOptions) WithFlushThld

func (opts *IndexOptions) WithFlushThld(flushThld int) *IndexOptions

func (*IndexOptions) WithMaxActiveSnapshots

func (opts *IndexOptions) WithMaxActiveSnapshots(maxActiveSnapshots int) *IndexOptions

func (*IndexOptions) WithMaxNodeSize

func (opts *IndexOptions) WithMaxNodeSize(maxNodeSize int) *IndexOptions

func (*IndexOptions) WithRenewSnapRootAfter

func (opts *IndexOptions) WithRenewSnapRootAfter(renewSnapRootAfter time.Duration) *IndexOptions

type IndexedValue added in v0.9.0

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

func (*IndexedValue) Resolve added in v0.9.0

func (v *IndexedValue) Resolve() ([]byte, error)

Resolve ...

type KV

type KV struct {
	Key   []byte
	Value []byte
}

func (*KV) Digest

func (kv *KV) Digest() [sha256.Size]byte

type LinearProof

type LinearProof struct {
	SourceTxID uint64
	TargetTxID uint64
	Terms      [][sha256.Size]byte
}

type Options

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

func DefaultOptions

func DefaultOptions() *Options

func (*Options) WithCommitLogMaxOpenedFiles

func (opts *Options) WithCommitLogMaxOpenedFiles(commitLogMaxOpenedFiles int) *Options

func (*Options) WithCompresionLevel

func (opts *Options) WithCompresionLevel(compressionLevel int) *Options

func (*Options) WithCompressionFormat

func (opts *Options) WithCompressionFormat(compressionFormat int) *Options

func (*Options) WithFileMode

func (opts *Options) WithFileMode(fileMode os.FileMode) *Options

func (*Options) WithFileSize

func (opts *Options) WithFileSize(fileSize int) *Options

func (*Options) WithIndexOptions

func (opts *Options) WithIndexOptions(indexOptions *IndexOptions) *Options

func (*Options) WithMaxConcurrency

func (opts *Options) WithMaxConcurrency(maxConcurrency int) *Options

func (*Options) WithMaxIOConcurrency

func (opts *Options) WithMaxIOConcurrency(maxIOConcurrency int) *Options

func (*Options) WithMaxKeyLen

func (opts *Options) WithMaxKeyLen(maxKeyLen int) *Options

func (*Options) WithMaxLinearProofLen

func (opts *Options) WithMaxLinearProofLen(maxLinearProofLen int) *Options

func (*Options) WithMaxTxEntries

func (opts *Options) WithMaxTxEntries(maxTxEntries int) *Options

func (*Options) WithMaxValueLen

func (opts *Options) WithMaxValueLen(maxValueLen int) *Options

func (*Options) WithReadOnly

func (opts *Options) WithReadOnly(readOnly bool) *Options

func (*Options) WithSynced

func (opts *Options) WithSynced(synced bool) *Options

func (*Options) WithTxLogMaxOpenedFiles

func (opts *Options) WithTxLogMaxOpenedFiles(txLogMaxOpenedFiles int) *Options

func (*Options) WithVLogMaxOpenedFiles

func (opts *Options) WithVLogMaxOpenedFiles(vLogMaxOpenedFiles int) *Options

type Reader added in v0.9.0

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

func (*Reader) Close added in v0.9.0

func (s *Reader) Close() error

func (*Reader) Read added in v0.9.0

func (s *Reader) Read() (key []byte, val *IndexedValue, tx uint64, err error)

type Tx

type Tx struct {
	ID      uint64
	Ts      int64
	BlTxID  uint64
	BlRoot  [sha256.Size]byte
	PrevAlh [sha256.Size]byte

	Alh       [sha256.Size]byte
	InnerHash [sha256.Size]byte
	// contains filtered or unexported fields
}

func NewTx added in v0.9.0

func NewTx(nentries int, maxKeyLen int) *Tx

func NewTxWithEntries added in v0.9.0

func NewTxWithEntries(entries []*Txe) *Tx

func (*Tx) BuildHashTree added in v0.9.0

func (tx *Tx) BuildHashTree() error

func (*Tx) CalcAlh added in v0.9.0

func (tx *Tx) CalcAlh()

Alh calculates the Accumulative Linear Hash up to this transaction Alh is calculated as hash(txID + prevAlh + hash(ts + nentries + eH + blTxID + blRoot)) Inner hash is calculated so to reduce the length of linear proofs

func (*Tx) Eh

func (tx *Tx) Eh() [sha256.Size]byte

func (*Tx) Entries

func (tx *Tx) Entries() []*Txe

func (*Tx) IndexOf

func (tx *Tx) IndexOf(key []byte) (int, error)

func (*Tx) Metadata added in v0.9.0

func (tx *Tx) Metadata() *TxMetadata

func (*Tx) Proof

func (tx *Tx) Proof(key []byte) (*htree.InclusionProof, error)

type TxMetadata

type TxMetadata struct {
	ID       uint64
	PrevAlh  [sha256.Size]byte
	Ts       int64
	NEntries int
	Eh       [sha256.Size]byte
	BlTxID   uint64
	BlRoot   [sha256.Size]byte
}

func (*TxMetadata) Alh added in v0.9.0

func (txMetadata *TxMetadata) Alh() [sha256.Size]byte

type TxReader

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

func (*TxReader) Read

func (txr *TxReader) Read() (*Tx, error)

type Txe

type Txe struct {
	ValueLen int
	HValue   [sha256.Size]byte
	VOff     int64
	// contains filtered or unexported fields
}

func (*Txe) Digest

func (e *Txe) Digest() [sha256.Size]byte

func (*Txe) Key

func (e *Txe) Key() []byte

func (*Txe) SetKey added in v0.9.0

func (e *Txe) SetKey(key []byte)

Jump to

Keyboard shortcuts

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