id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
20,200 | decred/dcrdata | db/dcrsqlite/sqlite.go | setHeightToSideChain | func (db *DB) setHeightToSideChain(height int64) error {
_, err := db.Exec(db.setHeightToSideChainSQL, height)
return db.filterError(err)
} | go | func (db *DB) setHeightToSideChain(height int64) error {
_, err := db.Exec(db.setHeightToSideChainSQL, height)
return db.filterError(err)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"setHeightToSideChain",
"(",
"height",
"int64",
")",
"error",
"{",
"_",
",",
"err",
":=",
"db",
".",
"Exec",
"(",
"db",
".",
"setHeightToSideChainSQL",
",",
"height",
")",
"\n",
"return",
"db",
".",
"filterError",
"("... | // Sets the is_mainchain field to false for the given block in the database. | [
"Sets",
"the",
"is_mainchain",
"field",
"to",
"false",
"for",
"the",
"given",
"block",
"in",
"the",
"database",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L638-L641 |
20,201 | decred/dcrdata | db/dcrsqlite/sqlite.go | getMainchainStatus | func (db *DB) getMainchainStatus(blockhash string) (bool, error) {
var isMainchain bool
err := db.QueryRow(db.getMainchainStatusSQL, blockhash).Scan(&isMainchain)
return isMainchain, err
} | go | func (db *DB) getMainchainStatus(blockhash string) (bool, error) {
var isMainchain bool
err := db.QueryRow(db.getMainchainStatusSQL, blockhash).Scan(&isMainchain)
return isMainchain, err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"getMainchainStatus",
"(",
"blockhash",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"isMainchain",
"bool",
"\n",
"err",
":=",
"db",
".",
"QueryRow",
"(",
"db",
".",
"getMainchainStatusSQL",
",",
"blockhas... | // Returns the is_mainchain value from the database for the given hash. | [
"Returns",
"the",
"is_mainchain",
"value",
"from",
"the",
"database",
"for",
"the",
"given",
"hash",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L644-L648 |
20,202 | decred/dcrdata | db/dcrsqlite/sqlite.go | StoreBlock | func (db *DB) StoreBlock(bd *apitypes.BlockDataBasic, isMainchain bool, isValid bool) error {
// Cache mainchain blocks.
if isMainchain && db.BlockCache != nil && db.BlockCache.IsEnabled() {
if err := db.BlockCache.StoreBlockSummary(bd); err != nil {
return fmt.Errorf("APICache failed to store block: %v", err)
... | go | func (db *DB) StoreBlock(bd *apitypes.BlockDataBasic, isMainchain bool, isValid bool) error {
// Cache mainchain blocks.
if isMainchain && db.BlockCache != nil && db.BlockCache.IsEnabled() {
if err := db.BlockCache.StoreBlockSummary(bd); err != nil {
return fmt.Errorf("APICache failed to store block: %v", err)
... | [
"func",
"(",
"db",
"*",
"DB",
")",
"StoreBlock",
"(",
"bd",
"*",
"apitypes",
".",
"BlockDataBasic",
",",
"isMainchain",
"bool",
",",
"isValid",
"bool",
")",
"error",
"{",
"// Cache mainchain blocks.",
"if",
"isMainchain",
"&&",
"db",
".",
"BlockCache",
"!=",... | // StoreBlock attempts to store the block data in the database, and
// returns an error on failure. | [
"StoreBlock",
"attempts",
"to",
"store",
"the",
"block",
"data",
"in",
"the",
"database",
"and",
"returns",
"an",
"error",
"on",
"failure",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L652-L696 |
20,203 | decred/dcrdata | db/dcrsqlite/sqlite.go | StoreBlockSummary | func (db *DB) StoreBlockSummary(bd *apitypes.BlockDataBasic) error {
return db.StoreBlock(bd, true, true)
} | go | func (db *DB) StoreBlockSummary(bd *apitypes.BlockDataBasic) error {
return db.StoreBlock(bd, true, true)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"StoreBlockSummary",
"(",
"bd",
"*",
"apitypes",
".",
"BlockDataBasic",
")",
"error",
"{",
"return",
"db",
".",
"StoreBlock",
"(",
"bd",
",",
"true",
",",
"true",
")",
"\n",
"}"
] | // StoreBlockSummary is called with new mainchain blocks. | [
"StoreBlockSummary",
"is",
"called",
"with",
"new",
"mainchain",
"blocks",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L699-L701 |
20,204 | decred/dcrdata | db/dcrsqlite/sqlite.go | StoreSideBlockSummary | func (db *DB) StoreSideBlockSummary(bd *apitypes.BlockDataBasic) error {
return db.StoreBlock(bd, false, true)
} | go | func (db *DB) StoreSideBlockSummary(bd *apitypes.BlockDataBasic) error {
return db.StoreBlock(bd, false, true)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"StoreSideBlockSummary",
"(",
"bd",
"*",
"apitypes",
".",
"BlockDataBasic",
")",
"error",
"{",
"return",
"db",
".",
"StoreBlock",
"(",
"bd",
",",
"false",
",",
"true",
")",
"\n",
"}"
] | // StoreSideBlockSummary is for storing side chain. | [
"StoreSideBlockSummary",
"is",
"for",
"storing",
"side",
"chain",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L704-L706 |
20,205 | decred/dcrdata | db/dcrsqlite/sqlite.go | GetBestBlockHash | func (db *DB) GetBestBlockHash() string {
hash, err := db.RetrieveBestBlockHash()
if err != nil {
log.Errorf("RetrieveBestBlockHash failed: %v", err)
return ""
}
return hash
} | go | func (db *DB) GetBestBlockHash() string {
hash, err := db.RetrieveBestBlockHash()
if err != nil {
log.Errorf("RetrieveBestBlockHash failed: %v", err)
return ""
}
return hash
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"GetBestBlockHash",
"(",
")",
"string",
"{",
"hash",
",",
"err",
":=",
"db",
".",
"RetrieveBestBlockHash",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"... | // GetBestBlockHash returns the hash of the best block. | [
"GetBestBlockHash",
"returns",
"the",
"hash",
"of",
"the",
"best",
"block",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L709-L716 |
20,206 | decred/dcrdata | db/dcrsqlite/sqlite.go | GetBlockSummaryHeight | func (db *DB) GetBlockSummaryHeight() (int64, error) {
db.mtx.RLock()
defer db.mtx.RUnlock()
if db.dbSummaryHeight < 0 {
h, err := db.getBlockSummaryHeight()
if err == nil {
db.dbSummaryHeight = h
}
return h, err
}
return db.dbSummaryHeight, nil
} | go | func (db *DB) GetBlockSummaryHeight() (int64, error) {
db.mtx.RLock()
defer db.mtx.RUnlock()
if db.dbSummaryHeight < 0 {
h, err := db.getBlockSummaryHeight()
if err == nil {
db.dbSummaryHeight = h
}
return h, err
}
return db.dbSummaryHeight, nil
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"GetBlockSummaryHeight",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"db",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"db",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"db",
".",
"dbSummaryHeig... | // GetBlockSummaryHeight returns the largest block height for which the database
// can provide a block summary. A cached best block summary height will be
// returned when available to avoid unnecessary DB queries. | [
"GetBlockSummaryHeight",
"returns",
"the",
"largest",
"block",
"height",
"for",
"which",
"the",
"database",
"can",
"provide",
"a",
"block",
"summary",
".",
"A",
"cached",
"best",
"block",
"summary",
"height",
"will",
"be",
"returned",
"when",
"available",
"to",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L765-L776 |
20,207 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrievePoolInfoRange | func (db *DB) RetrievePoolInfoRange(ind0, ind1 int64) ([]apitypes.TicketPoolInfo, []string, error) {
N := ind1 - ind0 + 1
if N == 0 {
return []apitypes.TicketPoolInfo{}, []string{}, nil
}
if N < 0 {
return nil, nil, fmt.Errorf("Cannot retrieve pool info range (%d>%d)",
ind0, ind1)
}
db.mtx.RLock()
if ind1... | go | func (db *DB) RetrievePoolInfoRange(ind0, ind1 int64) ([]apitypes.TicketPoolInfo, []string, error) {
N := ind1 - ind0 + 1
if N == 0 {
return []apitypes.TicketPoolInfo{}, []string{}, nil
}
if N < 0 {
return nil, nil, fmt.Errorf("Cannot retrieve pool info range (%d>%d)",
ind0, ind1)
}
db.mtx.RLock()
if ind1... | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrievePoolInfoRange",
"(",
"ind0",
",",
"ind1",
"int64",
")",
"(",
"[",
"]",
"apitypes",
".",
"TicketPoolInfo",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"N",
":=",
"ind1",
"-",
"ind0",
"+",
"1",
"\n",
... | // RetrievePoolInfoRange returns an array of apitypes.TicketPoolInfo for block
// range ind0 to ind1 and a non-nil error on success | [
"RetrievePoolInfoRange",
"returns",
"an",
"array",
"of",
"apitypes",
".",
"TicketPoolInfo",
"for",
"block",
"range",
"ind0",
"to",
"ind1",
"and",
"a",
"non",
"-",
"nil",
"error",
"on",
"success"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L834-L883 |
20,208 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrievePoolInfo | func (db *DB) RetrievePoolInfo(ind int64) (*apitypes.TicketPoolInfo, error) {
tpi := &apitypes.TicketPoolInfo{
Height: uint32(ind),
}
var hash, winners string
err := db.QueryRow(db.getPoolSQL, ind).Scan(&hash, &tpi.Size,
&tpi.Value, &tpi.ValAvg, &winners)
tpi.Winners = splitToArray(winners)
return tpi, err
} | go | func (db *DB) RetrievePoolInfo(ind int64) (*apitypes.TicketPoolInfo, error) {
tpi := &apitypes.TicketPoolInfo{
Height: uint32(ind),
}
var hash, winners string
err := db.QueryRow(db.getPoolSQL, ind).Scan(&hash, &tpi.Size,
&tpi.Value, &tpi.ValAvg, &winners)
tpi.Winners = splitToArray(winners)
return tpi, err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrievePoolInfo",
"(",
"ind",
"int64",
")",
"(",
"*",
"apitypes",
".",
"TicketPoolInfo",
",",
"error",
")",
"{",
"tpi",
":=",
"&",
"apitypes",
".",
"TicketPoolInfo",
"{",
"Height",
":",
"uint32",
"(",
"ind",
")",
... | // RetrievePoolInfo returns ticket pool info for block height ind | [
"RetrievePoolInfo",
"returns",
"ticket",
"pool",
"info",
"for",
"block",
"height",
"ind"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L886-L895 |
20,209 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveWinnersByHash | func (db *DB) RetrieveWinnersByHash(hash string) ([]string, uint32, error) {
var winners string
var height uint32
err := db.QueryRow(db.getWinnersByHashSQL, hash).Scan(&height, &winners)
if err != nil {
return nil, 0, err
}
return splitToArray(winners), height, err
} | go | func (db *DB) RetrieveWinnersByHash(hash string) ([]string, uint32, error) {
var winners string
var height uint32
err := db.QueryRow(db.getWinnersByHashSQL, hash).Scan(&height, &winners)
if err != nil {
return nil, 0, err
}
return splitToArray(winners), height, err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveWinnersByHash",
"(",
"hash",
"string",
")",
"(",
"[",
"]",
"string",
",",
"uint32",
",",
"error",
")",
"{",
"var",
"winners",
"string",
"\n",
"var",
"height",
"uint32",
"\n",
"err",
":=",
"db",
".",
"QueryR... | // RetrieveWinnersByHash returns the winning ticket tx IDs drawn after
// connecting the block with the given hash. The block height corresponding to
// the input block hash is also returned. | [
"RetrieveWinnersByHash",
"returns",
"the",
"winning",
"ticket",
"tx",
"IDs",
"drawn",
"after",
"connecting",
"the",
"block",
"with",
"the",
"given",
"hash",
".",
"The",
"block",
"height",
"corresponding",
"to",
"the",
"input",
"block",
"hash",
"is",
"also",
"r... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L912-L920 |
20,210 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrievePoolInfoByHash | func (db *DB) RetrievePoolInfoByHash(hash string) (*apitypes.TicketPoolInfo, error) {
tpi := new(apitypes.TicketPoolInfo)
var winners string
err := db.QueryRow(db.getPoolByHashSQL, hash).Scan(&tpi.Height, &tpi.Size,
&tpi.Value, &tpi.ValAvg, &winners)
tpi.Winners = splitToArray(winners)
return tpi, err
} | go | func (db *DB) RetrievePoolInfoByHash(hash string) (*apitypes.TicketPoolInfo, error) {
tpi := new(apitypes.TicketPoolInfo)
var winners string
err := db.QueryRow(db.getPoolByHashSQL, hash).Scan(&tpi.Height, &tpi.Size,
&tpi.Value, &tpi.ValAvg, &winners)
tpi.Winners = splitToArray(winners)
return tpi, err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrievePoolInfoByHash",
"(",
"hash",
"string",
")",
"(",
"*",
"apitypes",
".",
"TicketPoolInfo",
",",
"error",
")",
"{",
"tpi",
":=",
"new",
"(",
"apitypes",
".",
"TicketPoolInfo",
")",
"\n",
"var",
"winners",
"string... | // RetrievePoolInfoByHash returns ticket pool info for blockhash hash. | [
"RetrievePoolInfoByHash",
"returns",
"ticket",
"pool",
"info",
"for",
"blockhash",
"hash",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L923-L930 |
20,211 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrievePoolValAndSizeRange | func (db *DB) RetrievePoolValAndSizeRange(ind0, ind1 int64) ([]float64, []float64, error) {
N := ind1 - ind0 + 1
if N == 0 {
return []float64{}, []float64{}, nil
}
if N < 0 {
return nil, nil, fmt.Errorf("Cannot retrieve pool val and size range (%d>%d)",
ind0, ind1)
}
db.mtx.RLock()
if ind1 > db.dbSummaryH... | go | func (db *DB) RetrievePoolValAndSizeRange(ind0, ind1 int64) ([]float64, []float64, error) {
N := ind1 - ind0 + 1
if N == 0 {
return []float64{}, []float64{}, nil
}
if N < 0 {
return nil, nil, fmt.Errorf("Cannot retrieve pool val and size range (%d>%d)",
ind0, ind1)
}
db.mtx.RLock()
if ind1 > db.dbSummaryH... | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrievePoolValAndSizeRange",
"(",
"ind0",
",",
"ind1",
"int64",
")",
"(",
"[",
"]",
"float64",
",",
"[",
"]",
"float64",
",",
"error",
")",
"{",
"N",
":=",
"ind1",
"-",
"ind0",
"+",
"1",
"\n",
"if",
"N",
"==",... | // RetrievePoolValAndSizeRange returns an array each of the pool values and
// sizes for block range ind0 to ind1. | [
"RetrievePoolValAndSizeRange",
"returns",
"an",
"array",
"each",
"of",
"the",
"pool",
"values",
"and",
"sizes",
"for",
"block",
"range",
"ind0",
"to",
"ind1",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L934-L985 |
20,212 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrievePoolAllValueAndSize | func (db *DB) RetrievePoolAllValueAndSize(charts *cache.ChartData) (*sql.Rows, func(), error) {
stmt, err := db.Prepare(db.getAllPoolValSize)
if err != nil {
return nil, dummyCancel, err
}
defer stmt.Close()
rows, err := stmt.Query(charts.PoolSizeTip())
if err != nil {
log.Errorf("Query failed: %v", err)
r... | go | func (db *DB) RetrievePoolAllValueAndSize(charts *cache.ChartData) (*sql.Rows, func(), error) {
stmt, err := db.Prepare(db.getAllPoolValSize)
if err != nil {
return nil, dummyCancel, err
}
defer stmt.Close()
rows, err := stmt.Query(charts.PoolSizeTip())
if err != nil {
log.Errorf("Query failed: %v", err)
r... | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrievePoolAllValueAndSize",
"(",
"charts",
"*",
"cache",
".",
"ChartData",
")",
"(",
"*",
"sql",
".",
"Rows",
",",
"func",
"(",
")",
",",
"error",
")",
"{",
"stmt",
",",
"err",
":=",
"db",
".",
"Prepare",
"(",
... | // RetrievePoolAllValueAndSize returns all the pool value and the pool size
// charts data needed to plot ticket-pool-size and ticket-pool value charts on
// the charts page. This is the Fetcher half of a pair that make up a
// cache.ChartUpdater. | [
"RetrievePoolAllValueAndSize",
"returns",
"all",
"the",
"pool",
"value",
"and",
"the",
"pool",
"size",
"charts",
"data",
"needed",
"to",
"plot",
"ticket",
"-",
"pool",
"-",
"size",
"and",
"ticket",
"-",
"pool",
"value",
"charts",
"on",
"the",
"charts",
"page... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L993-L1006 |
20,213 | decred/dcrdata | db/dcrsqlite/sqlite.go | AppendPoolAllValueAndSize | func (db *DB) AppendPoolAllValueAndSize(charts *cache.ChartData, rows *sql.Rows) error {
defer rows.Close()
blocks := charts.Blocks
for rows.Next() {
var pval, psize float64
var timestamp int64
if err := rows.Scan(&psize, &pval, ×tamp); err != nil {
log.Errorf("Unable to scan for TicketPoolInfo fields:... | go | func (db *DB) AppendPoolAllValueAndSize(charts *cache.ChartData, rows *sql.Rows) error {
defer rows.Close()
blocks := charts.Blocks
for rows.Next() {
var pval, psize float64
var timestamp int64
if err := rows.Scan(&psize, &pval, ×tamp); err != nil {
log.Errorf("Unable to scan for TicketPoolInfo fields:... | [
"func",
"(",
"db",
"*",
"DB",
")",
"AppendPoolAllValueAndSize",
"(",
"charts",
"*",
"cache",
".",
"ChartData",
",",
"rows",
"*",
"sql",
".",
"Rows",
")",
"error",
"{",
"defer",
"rows",
".",
"Close",
"(",
")",
"\n",
"blocks",
":=",
"charts",
".",
"Blo... | // Append the result from RetrievePoolAllValueAndSize to the provided ChartData.
// This is the Appender half of a pair that make up a cache.ChartUpdater. | [
"Append",
"the",
"result",
"from",
"RetrievePoolAllValueAndSize",
"to",
"the",
"provided",
"ChartData",
".",
"This",
"is",
"the",
"Appender",
"half",
"of",
"a",
"pair",
"that",
"make",
"up",
"a",
"cache",
".",
"ChartUpdater",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1010-L1030 |
20,214 | decred/dcrdata | db/dcrsqlite/sqlite.go | AppendBlockFeeRows | func (db *DB) AppendBlockFeeRows(charts *cache.ChartData, rows *sql.Rows) error {
defer rows.Close()
blocks := charts.Blocks
for rows.Next() {
var feeMed float64
var blockHeight uint64
if err := rows.Scan(&blockHeight, &feeMed); err != nil {
log.Errorf("Unable to scan for FeeInfoPerBlock fields: %v", err)
... | go | func (db *DB) AppendBlockFeeRows(charts *cache.ChartData, rows *sql.Rows) error {
defer rows.Close()
blocks := charts.Blocks
for rows.Next() {
var feeMed float64
var blockHeight uint64
if err := rows.Scan(&blockHeight, &feeMed); err != nil {
log.Errorf("Unable to scan for FeeInfoPerBlock fields: %v", err)
... | [
"func",
"(",
"db",
"*",
"DB",
")",
"AppendBlockFeeRows",
"(",
"charts",
"*",
"cache",
".",
"ChartData",
",",
"rows",
"*",
"sql",
".",
"Rows",
")",
"error",
"{",
"defer",
"rows",
".",
"Close",
"(",
")",
"\n",
"blocks",
":=",
"charts",
".",
"Blocks",
... | // Append the result from RetrieveBlockFeeRows to the provided ChartData. This
// is the Appender half of a pair that make up a cache.ChartUpdater. | [
"Append",
"the",
"result",
"from",
"RetrieveBlockFeeRows",
"to",
"the",
"provided",
"ChartData",
".",
"This",
"is",
"the",
"Appender",
"half",
"of",
"a",
"pair",
"that",
"make",
"up",
"a",
"cache",
".",
"ChartUpdater",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1053-L1069 |
20,215 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveSDiffRange | func (db *DB) RetrieveSDiffRange(ind0, ind1 int64) ([]float64, error) {
N := ind1 - ind0 + 1
if N == 0 {
return []float64{}, nil
}
if N < 0 {
return nil, fmt.Errorf("Cannot retrieve sdiff range (%d>%d)",
ind0, ind1)
}
db.mtx.RLock()
if ind1 > db.dbSummaryHeight || ind0 < 0 {
defer db.mtx.RUnlock()
ret... | go | func (db *DB) RetrieveSDiffRange(ind0, ind1 int64) ([]float64, error) {
N := ind1 - ind0 + 1
if N == 0 {
return []float64{}, nil
}
if N < 0 {
return nil, fmt.Errorf("Cannot retrieve sdiff range (%d>%d)",
ind0, ind1)
}
db.mtx.RLock()
if ind1 > db.dbSummaryHeight || ind0 < 0 {
defer db.mtx.RUnlock()
ret... | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveSDiffRange",
"(",
"ind0",
",",
"ind1",
"int64",
")",
"(",
"[",
"]",
"float64",
",",
"error",
")",
"{",
"N",
":=",
"ind1",
"-",
"ind0",
"+",
"1",
"\n",
"if",
"N",
"==",
"0",
"{",
"return",
"[",
"]",
... | // RetrieveSDiffRange returns an array of stake difficulties for block range ind0 to
// ind1 | [
"RetrieveSDiffRange",
"returns",
"an",
"array",
"of",
"stake",
"difficulties",
"for",
"block",
"range",
"ind0",
"to",
"ind1"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1073-L1117 |
20,216 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveDiff | func (db *DB) RetrieveDiff(timestamp int64) (float64, error) {
var diff float64
err := db.QueryRow(db.getDifficulty, timestamp).Scan(&diff)
return diff, err
} | go | func (db *DB) RetrieveDiff(timestamp int64) (float64, error) {
var diff float64
err := db.QueryRow(db.getDifficulty, timestamp).Scan(&diff)
return diff, err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveDiff",
"(",
"timestamp",
"int64",
")",
"(",
"float64",
",",
"error",
")",
"{",
"var",
"diff",
"float64",
"\n",
"err",
":=",
"db",
".",
"QueryRow",
"(",
"db",
".",
"getDifficulty",
",",
"timestamp",
")",
"."... | // RetrieveDiff returns the difficulty in the last 24hrs or immediately after
// 24hrs. | [
"RetrieveDiff",
"returns",
"the",
"difficulty",
"in",
"the",
"last",
"24hrs",
"or",
"immediately",
"after",
"24hrs",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1157-L1161 |
20,217 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveSDiff | func (db *DB) RetrieveSDiff(ind int64) (float64, error) {
var sdiff float64
err := db.QueryRow(db.getSDiffSQL, ind).Scan(&sdiff)
return sdiff, err
} | go | func (db *DB) RetrieveSDiff(ind int64) (float64, error) {
var sdiff float64
err := db.QueryRow(db.getSDiffSQL, ind).Scan(&sdiff)
return sdiff, err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveSDiff",
"(",
"ind",
"int64",
")",
"(",
"float64",
",",
"error",
")",
"{",
"var",
"sdiff",
"float64",
"\n",
"err",
":=",
"db",
".",
"QueryRow",
"(",
"db",
".",
"getSDiffSQL",
",",
"ind",
")",
".",
"Scan",
... | // RetrieveSDiff returns the stake difficulty for block at the specified chain
// height. | [
"RetrieveSDiff",
"returns",
"the",
"stake",
"difficulty",
"for",
"block",
"at",
"the",
"specified",
"chain",
"height",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1165-L1169 |
20,218 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveBlockHash | func (db *DB) RetrieveBlockHash(ind int64) (string, error) {
// First try the block summary cache.
usingBlockCache := db.BlockCache != nil && db.BlockCache.IsEnabled()
if usingBlockCache {
hash := db.BlockCache.GetBlockHash(ind)
if hash != "" {
// Cache hit!
return hash, nil
}
// Cache miss necessitate... | go | func (db *DB) RetrieveBlockHash(ind int64) (string, error) {
// First try the block summary cache.
usingBlockCache := db.BlockCache != nil && db.BlockCache.IsEnabled()
if usingBlockCache {
hash := db.BlockCache.GetBlockHash(ind)
if hash != "" {
// Cache hit!
return hash, nil
}
// Cache miss necessitate... | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveBlockHash",
"(",
"ind",
"int64",
")",
"(",
"string",
",",
"error",
")",
"{",
"// First try the block summary cache.",
"usingBlockCache",
":=",
"db",
".",
"BlockCache",
"!=",
"nil",
"&&",
"db",
".",
"BlockCache",
".... | // RetrieveBlockHash returns the block hash for block ind | [
"RetrieveBlockHash",
"returns",
"the",
"block",
"hash",
"for",
"block",
"ind"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1191-L1206 |
20,219 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveBlockHeight | func (db *DB) RetrieveBlockHeight(hash string) (int64, error) {
var blockHeight int64
err := db.QueryRow(db.getBlockHeightSQL, hash).Scan(&blockHeight)
return blockHeight, err
} | go | func (db *DB) RetrieveBlockHeight(hash string) (int64, error) {
var blockHeight int64
err := db.QueryRow(db.getBlockHeightSQL, hash).Scan(&blockHeight)
return blockHeight, err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveBlockHeight",
"(",
"hash",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"var",
"blockHeight",
"int64",
"\n",
"err",
":=",
"db",
".",
"QueryRow",
"(",
"db",
".",
"getBlockHeightSQL",
",",
"hash",
")",
... | // RetrieveBlockHeight returns the block height for blockhash hash | [
"RetrieveBlockHeight",
"returns",
"the",
"block",
"height",
"for",
"blockhash",
"hash"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1209-L1213 |
20,220 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveHighestBlockHash | func (db *DB) RetrieveHighestBlockHash() (string, error) {
var blockHash string
err := db.QueryRow(db.getHighestBlockHashSQL).Scan(&blockHash)
return blockHash, err
} | go | func (db *DB) RetrieveHighestBlockHash() (string, error) {
var blockHash string
err := db.QueryRow(db.getHighestBlockHashSQL).Scan(&blockHash)
return blockHash, err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveHighestBlockHash",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"blockHash",
"string",
"\n",
"err",
":=",
"db",
".",
"QueryRow",
"(",
"db",
".",
"getHighestBlockHashSQL",
")",
".",
"Scan",
"(",
"&"... | // RetrieveHighestBlockHash returns the block hash for the highest block,
// regardless of mainchain status. | [
"RetrieveHighestBlockHash",
"returns",
"the",
"block",
"hash",
"for",
"the",
"highest",
"block",
"regardless",
"of",
"mainchain",
"status",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1224-L1228 |
20,221 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveBestBlockHeight | func (db *DB) RetrieveBestBlockHeight() (int64, error) {
var blockHeight int64
err := db.QueryRow(db.getBestBlockHeightSQL).Scan(&blockHeight)
return blockHeight, err
} | go | func (db *DB) RetrieveBestBlockHeight() (int64, error) {
var blockHeight int64
err := db.QueryRow(db.getBestBlockHeightSQL).Scan(&blockHeight)
return blockHeight, err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveBestBlockHeight",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"var",
"blockHeight",
"int64",
"\n",
"err",
":=",
"db",
".",
"QueryRow",
"(",
"db",
".",
"getBestBlockHeightSQL",
")",
".",
"Scan",
"(",
"&",
... | // RetrieveBestBlockHeight returns the block height for the best block | [
"RetrieveBestBlockHeight",
"returns",
"the",
"block",
"height",
"for",
"the",
"best",
"block"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1231-L1235 |
20,222 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveHighestBlockHeight | func (db *DB) RetrieveHighestBlockHeight() (int64, error) {
var blockHeight int64
err := db.QueryRow(db.getHighestBlockHeightSQL).Scan(&blockHeight)
return blockHeight, err
} | go | func (db *DB) RetrieveHighestBlockHeight() (int64, error) {
var blockHeight int64
err := db.QueryRow(db.getHighestBlockHeightSQL).Scan(&blockHeight)
return blockHeight, err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveHighestBlockHeight",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"var",
"blockHeight",
"int64",
"\n",
"err",
":=",
"db",
".",
"QueryRow",
"(",
"db",
".",
"getHighestBlockHeightSQL",
")",
".",
"Scan",
"(",
... | // RetrieveHighestBlockHeight returns the block height for the highest block,
// regardless of mainchain status. | [
"RetrieveHighestBlockHeight",
"returns",
"the",
"block",
"height",
"for",
"the",
"highest",
"block",
"regardless",
"of",
"mainchain",
"status",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1239-L1243 |
20,223 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveBlockSummaryByHash | func (db *DB) RetrieveBlockSummaryByHash(hash string) (*apitypes.BlockDataBasic, error) {
// First try the block summary cache.
usingBlockCache := db.BlockCache != nil && db.BlockCache.IsEnabled()
if usingBlockCache {
if bd := db.BlockCache.GetBlockSummaryByHash(hash); bd != nil {
// Cache hit!
return bd, ni... | go | func (db *DB) RetrieveBlockSummaryByHash(hash string) (*apitypes.BlockDataBasic, error) {
// First try the block summary cache.
usingBlockCache := db.BlockCache != nil && db.BlockCache.IsEnabled()
if usingBlockCache {
if bd := db.BlockCache.GetBlockSummaryByHash(hash); bd != nil {
// Cache hit!
return bd, ni... | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveBlockSummaryByHash",
"(",
"hash",
"string",
")",
"(",
"*",
"apitypes",
".",
"BlockDataBasic",
",",
"error",
")",
"{",
"// First try the block summary cache.",
"usingBlockCache",
":=",
"db",
".",
"BlockCache",
"!=",
"ni... | // RetrieveBlockSummaryByHash returns basic block data for a block given its hash | [
"RetrieveBlockSummaryByHash",
"returns",
"basic",
"block",
"data",
"for",
"a",
"block",
"given",
"its",
"hash"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1246-L1282 |
20,224 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveBlockSize | func (db *DB) RetrieveBlockSize(ind int64) (int32, error) {
// First try the block summary cache.
usingBlockCache := db.BlockCache != nil && db.BlockCache.IsEnabled()
if usingBlockCache {
sz := db.BlockCache.GetBlockSize(ind)
if sz != -1 {
// Cache hit!
return sz, nil
}
// Cache miss necessitates a DB ... | go | func (db *DB) RetrieveBlockSize(ind int64) (int32, error) {
// First try the block summary cache.
usingBlockCache := db.BlockCache != nil && db.BlockCache.IsEnabled()
if usingBlockCache {
sz := db.BlockCache.GetBlockSize(ind)
if sz != -1 {
// Cache hit!
return sz, nil
}
// Cache miss necessitates a DB ... | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveBlockSize",
"(",
"ind",
"int64",
")",
"(",
"int32",
",",
"error",
")",
"{",
"// First try the block summary cache.",
"usingBlockCache",
":=",
"db",
".",
"BlockCache",
"!=",
"nil",
"&&",
"db",
".",
"BlockCache",
"."... | // RetrieveBlockSize return the size of block at height ind. | [
"RetrieveBlockSize",
"return",
"the",
"size",
"of",
"block",
"at",
"height",
"ind",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1359-L1386 |
20,225 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveBlockSizeRange | func (db *DB) RetrieveBlockSizeRange(ind0, ind1 int64) ([]int32, error) {
N := ind1 - ind0 + 1
if N == 0 {
return []int32{}, nil
}
if N < 0 {
return nil, fmt.Errorf("Cannot retrieve block size range (%d>%d)",
ind0, ind1)
}
db.mtx.RLock()
if ind1 > db.dbSummaryHeight || ind0 < 0 {
defer db.mtx.RUnlock()
... | go | func (db *DB) RetrieveBlockSizeRange(ind0, ind1 int64) ([]int32, error) {
N := ind1 - ind0 + 1
if N == 0 {
return []int32{}, nil
}
if N < 0 {
return nil, fmt.Errorf("Cannot retrieve block size range (%d>%d)",
ind0, ind1)
}
db.mtx.RLock()
if ind1 > db.dbSummaryHeight || ind0 < 0 {
defer db.mtx.RUnlock()
... | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveBlockSizeRange",
"(",
"ind0",
",",
"ind1",
"int64",
")",
"(",
"[",
"]",
"int32",
",",
"error",
")",
"{",
"N",
":=",
"ind1",
"-",
"ind0",
"+",
"1",
"\n",
"if",
"N",
"==",
"0",
"{",
"return",
"[",
"]",
... | // RetrieveBlockSizeRange returns an array of block sizes for block range ind0 to ind1 | [
"RetrieveBlockSizeRange",
"returns",
"an",
"array",
"of",
"block",
"sizes",
"for",
"block",
"range",
"ind0",
"to",
"ind1"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1389-L1433 |
20,226 | decred/dcrdata | db/dcrsqlite/sqlite.go | StoreStakeInfoExtended | func (db *DB) StoreStakeInfoExtended(si *apitypes.StakeInfoExtended) error {
if db.BlockCache != nil && db.BlockCache.IsEnabled() {
if err := db.BlockCache.StoreStakeInfo(si); err != nil {
return fmt.Errorf("APICache failed to store stake info: %v", err)
}
}
stmt, err := db.Prepare(db.insertStakeInfoExtended... | go | func (db *DB) StoreStakeInfoExtended(si *apitypes.StakeInfoExtended) error {
if db.BlockCache != nil && db.BlockCache.IsEnabled() {
if err := db.BlockCache.StoreStakeInfo(si); err != nil {
return fmt.Errorf("APICache failed to store stake info: %v", err)
}
}
stmt, err := db.Prepare(db.insertStakeInfoExtended... | [
"func",
"(",
"db",
"*",
"DB",
")",
"StoreStakeInfoExtended",
"(",
"si",
"*",
"apitypes",
".",
"StakeInfoExtended",
")",
"error",
"{",
"if",
"db",
".",
"BlockCache",
"!=",
"nil",
"&&",
"db",
".",
"BlockCache",
".",
"IsEnabled",
"(",
")",
"{",
"if",
"err... | // StoreStakeInfoExtended stores the extended stake info in the database. | [
"StoreStakeInfoExtended",
"stores",
"the",
"extended",
"stake",
"info",
"in",
"the",
"database",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1436-L1476 |
20,227 | decred/dcrdata | db/dcrsqlite/sqlite.go | deleteStakeInfo | func (db *DB) deleteStakeInfo(blockhash string) (int64, error) {
res, err := db.Exec(db.deleteBlockByHashSQL, blockhash)
if err != nil {
return 0, db.filterError(err)
}
return res.RowsAffected()
} | go | func (db *DB) deleteStakeInfo(blockhash string) (int64, error) {
res, err := db.Exec(db.deleteBlockByHashSQL, blockhash)
if err != nil {
return 0, db.filterError(err)
}
return res.RowsAffected()
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"deleteStakeInfo",
"(",
"blockhash",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"db",
".",
"Exec",
"(",
"db",
".",
"deleteBlockByHashSQL",
",",
"blockhash",
")",
"\n",
"if",
"err",... | // Delete stake info for block with the given hash. The number of rows deleted
// is returned. | [
"Delete",
"stake",
"info",
"for",
"block",
"with",
"the",
"given",
"hash",
".",
"The",
"number",
"of",
"rows",
"deleted",
"is",
"returned",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1480-L1486 |
20,228 | decred/dcrdata | db/dcrsqlite/sqlite.go | deleteStakeInfoHeightMainchain | func (db *DB) deleteStakeInfoHeightMainchain(height int64) (int64, error) {
res, err := db.Exec(db.deleteBlockByHeightMainChainSQL, height)
if err != nil {
return 0, db.filterError(err)
}
return res.RowsAffected()
} | go | func (db *DB) deleteStakeInfoHeightMainchain(height int64) (int64, error) {
res, err := db.Exec(db.deleteBlockByHeightMainChainSQL, height)
if err != nil {
return 0, db.filterError(err)
}
return res.RowsAffected()
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"deleteStakeInfoHeightMainchain",
"(",
"height",
"int64",
")",
"(",
"int64",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"db",
".",
"Exec",
"(",
"db",
".",
"deleteBlockByHeightMainChainSQL",
",",
"height",
")",
"\n... | // Delete stake info for block at the given height on the main chain. The number
// of rows deleted is returned. | [
"Delete",
"stake",
"info",
"for",
"block",
"at",
"the",
"given",
"height",
"on",
"the",
"main",
"chain",
".",
"The",
"number",
"of",
"rows",
"deleted",
"is",
"returned",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1490-L1496 |
20,229 | decred/dcrdata | db/dcrsqlite/sqlite.go | RetrieveHighestStakeHeight | func (db *DB) RetrieveHighestStakeHeight() (int64, error) {
var height int64
err := db.QueryRow(db.getHighestStakeHeightSQL).Scan(&height)
if err != nil {
return -1, err
}
return height, nil
} | go | func (db *DB) RetrieveHighestStakeHeight() (int64, error) {
var height int64
err := db.QueryRow(db.getHighestStakeHeightSQL).Scan(&height)
if err != nil {
return -1, err
}
return height, nil
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"RetrieveHighestStakeHeight",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"var",
"height",
"int64",
"\n",
"err",
":=",
"db",
".",
"QueryRow",
"(",
"db",
".",
"getHighestStakeHeightSQL",
")",
".",
"Scan",
"(",
"&",... | // RetrieveHighestStakeHeight retrieves the height of the highest block in the
// stake table without regard to mainchain status. | [
"RetrieveHighestStakeHeight",
"retrieves",
"the",
"height",
"of",
"the",
"highest",
"block",
"in",
"the",
"stake",
"table",
"without",
"regard",
"to",
"mainchain",
"status",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1545-L1552 |
20,230 | decred/dcrdata | db/dcrsqlite/sqlite.go | getTip | func (db *DB) getTip() (*apitypes.BlockDataBasic, error) {
db.mtx.RLock()
defer db.mtx.RUnlock()
if db.lastStoredBlock != nil {
return db.lastStoredBlock, nil
}
return db.RetrieveLatestBlockSummary()
} | go | func (db *DB) getTip() (*apitypes.BlockDataBasic, error) {
db.mtx.RLock()
defer db.mtx.RUnlock()
if db.lastStoredBlock != nil {
return db.lastStoredBlock, nil
}
return db.RetrieveLatestBlockSummary()
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"getTip",
"(",
")",
"(",
"*",
"apitypes",
".",
"BlockDataBasic",
",",
"error",
")",
"{",
"db",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"db",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"db",
... | // getTip returns the last block stored using StoreBlockSummary.
// If no block has been stored yet, it returns the best block in the database. | [
"getTip",
"returns",
"the",
"last",
"block",
"stored",
"using",
"StoreBlockSummary",
".",
"If",
"no",
"block",
"has",
"been",
"stored",
"yet",
"it",
"returns",
"the",
"best",
"block",
"in",
"the",
"database",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/sqlite.go#L1783-L1790 |
20,231 | decred/dcrdata | stakedb/stakedb.go | NewPoolInfoCache | func NewPoolInfoCache(size int) (*PoolInfoCache, error) {
if size < 2 {
return nil, fmt.Errorf("size %d is less than 2", size)
}
return &PoolInfoCache{
poolInfo: make(map[chainhash.Hash]*apitypes.TicketPoolInfo, size),
expireQueue: make([]chainhash.Hash, 0, size),
maxSize: size,
}, nil
} | go | func NewPoolInfoCache(size int) (*PoolInfoCache, error) {
if size < 2 {
return nil, fmt.Errorf("size %d is less than 2", size)
}
return &PoolInfoCache{
poolInfo: make(map[chainhash.Hash]*apitypes.TicketPoolInfo, size),
expireQueue: make([]chainhash.Hash, 0, size),
maxSize: size,
}, nil
} | [
"func",
"NewPoolInfoCache",
"(",
"size",
"int",
")",
"(",
"*",
"PoolInfoCache",
",",
"error",
")",
"{",
"if",
"size",
"<",
"2",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"size",
")",
"\n",
"}",
"\n",
"return",
"&",
"P... | // NewPoolInfoCache constructs a new PoolInfoCache, and is needed to initialize
// the internal map. | [
"NewPoolInfoCache",
"constructs",
"a",
"new",
"PoolInfoCache",
"and",
"is",
"needed",
"to",
"initialize",
"the",
"internal",
"map",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L39-L48 |
20,232 | decred/dcrdata | stakedb/stakedb.go | Set | func (c *PoolInfoCache) Set(hash chainhash.Hash, p *apitypes.TicketPoolInfo) {
c.mtx.Lock()
defer c.mtx.Unlock()
c.poolInfo[hash] = p
if len(c.expireQueue)+1 >= c.maxSize {
expireHash := c.expireQueue[0]
c.expireQueue = c.expireQueue[1:]
delete(c.poolInfo, expireHash)
}
c.expireQueue = append(c.expireQueue,... | go | func (c *PoolInfoCache) Set(hash chainhash.Hash, p *apitypes.TicketPoolInfo) {
c.mtx.Lock()
defer c.mtx.Unlock()
c.poolInfo[hash] = p
if len(c.expireQueue)+1 >= c.maxSize {
expireHash := c.expireQueue[0]
c.expireQueue = c.expireQueue[1:]
delete(c.poolInfo, expireHash)
}
c.expireQueue = append(c.expireQueue,... | [
"func",
"(",
"c",
"*",
"PoolInfoCache",
")",
"Set",
"(",
"hash",
"chainhash",
".",
"Hash",
",",
"p",
"*",
"apitypes",
".",
"TicketPoolInfo",
")",
"{",
"c",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mtx",
".",
"Unlock",
"(",
")"... | // Set stores the ticket pool info for the given hash in the pool info cache. | [
"Set",
"stores",
"the",
"ticket",
"pool",
"info",
"for",
"the",
"given",
"hash",
"in",
"the",
"pool",
"info",
"cache",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L61-L71 |
20,233 | decred/dcrdata | stakedb/stakedb.go | SetCapacity | func (c *PoolInfoCache) SetCapacity(size int) error {
if size < 2 {
return fmt.Errorf("size %d is less than 2", size)
}
c.mtx.Lock()
defer c.mtx.Unlock()
c.maxSize = size
for len(c.expireQueue) >= c.maxSize {
expireHash := c.expireQueue[0]
c.expireQueue = c.expireQueue[1:]
delete(c.poolInfo, expireHash)
... | go | func (c *PoolInfoCache) SetCapacity(size int) error {
if size < 2 {
return fmt.Errorf("size %d is less than 2", size)
}
c.mtx.Lock()
defer c.mtx.Unlock()
c.maxSize = size
for len(c.expireQueue) >= c.maxSize {
expireHash := c.expireQueue[0]
c.expireQueue = c.expireQueue[1:]
delete(c.poolInfo, expireHash)
... | [
"func",
"(",
"c",
"*",
"PoolInfoCache",
")",
"SetCapacity",
"(",
"size",
"int",
")",
"error",
"{",
"if",
"size",
"<",
"2",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"size",
")",
"\n",
"}",
"\n\n",
"c",
".",
"mtx",
".",
"Lock",
... | // SetCapacity sets the cache capacity to the specified number of elements. If
// the new capacity is smaller than the current cache size, elements are
// automatically evicted until the desired size is reached. | [
"SetCapacity",
"sets",
"the",
"cache",
"capacity",
"to",
"the",
"specified",
"number",
"of",
"elements",
".",
"If",
"the",
"new",
"capacity",
"is",
"smaller",
"than",
"the",
"current",
"cache",
"size",
"elements",
"are",
"automatically",
"evicted",
"until",
"t... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L76-L90 |
20,234 | decred/dcrdata | stakedb/stakedb.go | PopulateLiveTicketCache | func (db *StakeDatabase) PopulateLiveTicketCache() error {
var err error
// Live tickets from dcrdata's stake Node's perspective
liveTickets := db.BestNode.LiveTickets()
log.Info("Pre-populating live ticket cache and computing pool value...")
// Send all the live ticket requests
type promiseGetRawTransaction st... | go | func (db *StakeDatabase) PopulateLiveTicketCache() error {
var err error
// Live tickets from dcrdata's stake Node's perspective
liveTickets := db.BestNode.LiveTickets()
log.Info("Pre-populating live ticket cache and computing pool value...")
// Send all the live ticket requests
type promiseGetRawTransaction st... | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"PopulateLiveTicketCache",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"// Live tickets from dcrdata's stake Node's perspective",
"liveTickets",
":=",
"db",
".",
"BestNode",
".",
"LiveTickets",
"(",
")",
"\n\n",... | // PopulateLiveTicketCache loads the hashes of all tickets in BestNode into the
// cache and computes the internally-stored pool value. | [
"PopulateLiveTicketCache",
"loads",
"the",
"hashes",
"of",
"all",
"tickets",
"in",
"BestNode",
"into",
"the",
"cache",
"and",
"computes",
"the",
"internally",
"-",
"stored",
"pool",
"value",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L327-L373 |
20,235 | decred/dcrdata | stakedb/stakedb.go | Rewind | func (db *StakeDatabase) Rewind(to int64, neglectCache bool) error {
var heightTicketPool int64
heightStakeDB := int64(db.Height())
for to < heightStakeDB {
if err := db.DisconnectBlock(neglectCache); err != nil {
return fmt.Errorf("failed to disconnect block: %v", err)
}
heightStakeDB, heightTicketPool = i... | go | func (db *StakeDatabase) Rewind(to int64, neglectCache bool) error {
var heightTicketPool int64
heightStakeDB := int64(db.Height())
for to < heightStakeDB {
if err := db.DisconnectBlock(neglectCache); err != nil {
return fmt.Errorf("failed to disconnect block: %v", err)
}
heightStakeDB, heightTicketPool = i... | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"Rewind",
"(",
"to",
"int64",
",",
"neglectCache",
"bool",
")",
"error",
"{",
"var",
"heightTicketPool",
"int64",
"\n",
"heightStakeDB",
":=",
"int64",
"(",
"db",
".",
"Height",
"(",
")",
")",
"\n",
"for",
... | // Rewind disconnects blocks until the new height is the specified height.
// During disconnect, the ticket pool cache and value are kept accurate, unless
// neglectCache is true. | [
"Rewind",
"disconnects",
"blocks",
"until",
"the",
"new",
"height",
"is",
"the",
"specified",
"height",
".",
"During",
"disconnect",
"the",
"ticket",
"pool",
"cache",
"and",
"value",
"are",
"kept",
"accurate",
"unless",
"neglectCache",
"is",
"true",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L378-L393 |
20,236 | decred/dcrdata | stakedb/stakedb.go | WaitForHeight | func (db *StakeDatabase) WaitForHeight(height int64) chan *chainhash.Hash {
dbHeight := int64(db.Height())
waitChan := make(chan *chainhash.Hash, 1)
if dbHeight > height {
defer func() { waitChan <- nil }()
return waitChan
} else if dbHeight == height {
block, _ := db.block(height)
if block == nil {
pani... | go | func (db *StakeDatabase) WaitForHeight(height int64) chan *chainhash.Hash {
dbHeight := int64(db.Height())
waitChan := make(chan *chainhash.Hash, 1)
if dbHeight > height {
defer func() { waitChan <- nil }()
return waitChan
} else if dbHeight == height {
block, _ := db.block(height)
if block == nil {
pani... | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"WaitForHeight",
"(",
"height",
"int64",
")",
"chan",
"*",
"chainhash",
".",
"Hash",
"{",
"dbHeight",
":=",
"int64",
"(",
"db",
".",
"Height",
"(",
")",
")",
"\n",
"waitChan",
":=",
"make",
"(",
"chan",
"... | // WaitForHeight provides a notification channel to which the hash of the block
// at the requested height will be sent when it becomes available. | [
"WaitForHeight",
"provides",
"a",
"notification",
"channel",
"to",
"which",
"the",
"hash",
"of",
"the",
"block",
"at",
"the",
"requested",
"height",
"will",
"be",
"sent",
"when",
"it",
"becomes",
"available",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L407-L424 |
20,237 | decred/dcrdata | stakedb/stakedb.go | BlockCached | func (db *StakeDatabase) BlockCached(ind int64) (*dcrutil.Block, bool) {
db.blkMtx.RLock()
defer db.blkMtx.RUnlock()
block, found := db.blockCache[ind]
return block, found
} | go | func (db *StakeDatabase) BlockCached(ind int64) (*dcrutil.Block, bool) {
db.blkMtx.RLock()
defer db.blkMtx.RUnlock()
block, found := db.blockCache[ind]
return block, found
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"BlockCached",
"(",
"ind",
"int64",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"bool",
")",
"{",
"db",
".",
"blkMtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"db",
".",
"blkMtx",
".",
"RUnlock",
"(",
... | // BlockCached attempts to find the block at the specified height in the block
// cache. The returned boolean indicates if it was found. | [
"BlockCached",
"attempts",
"to",
"find",
"the",
"block",
"at",
"the",
"specified",
"height",
"in",
"the",
"block",
"cache",
".",
"The",
"returned",
"boolean",
"indicates",
"if",
"it",
"was",
"found",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L456-L461 |
20,238 | decred/dcrdata | stakedb/stakedb.go | block | func (db *StakeDatabase) block(ind int64) (*dcrutil.Block, bool) {
block, ok := db.BlockCached(ind)
if !ok {
var err error
block, _, err = rpcutils.GetBlock(ind, db.NodeClient)
if err != nil {
log.Error(err)
return nil, false
}
}
return block, ok
} | go | func (db *StakeDatabase) block(ind int64) (*dcrutil.Block, bool) {
block, ok := db.BlockCached(ind)
if !ok {
var err error
block, _, err = rpcutils.GetBlock(ind, db.NodeClient)
if err != nil {
log.Error(err)
return nil, false
}
}
return block, ok
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"block",
"(",
"ind",
"int64",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"bool",
")",
"{",
"block",
",",
"ok",
":=",
"db",
".",
"BlockCached",
"(",
"ind",
")",
"\n",
"if",
"!",
"ok",
"{",
"var",
"... | // block first tries to find the block at the input height in cache, and if that
// fails it will request it from the node RPC client. Don't use this casually
// since reorganization may redefine a block at a given height. | [
"block",
"first",
"tries",
"to",
"find",
"the",
"block",
"at",
"the",
"input",
"height",
"in",
"cache",
"and",
"if",
"that",
"fails",
"it",
"will",
"request",
"it",
"from",
"the",
"node",
"RPC",
"client",
".",
"Don",
"t",
"use",
"this",
"casually",
"si... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L466-L477 |
20,239 | decred/dcrdata | stakedb/stakedb.go | ForgetBlock | func (db *StakeDatabase) ForgetBlock(ind int64) {
db.blkMtx.Lock()
defer db.blkMtx.Unlock()
delete(db.blockCache, ind)
} | go | func (db *StakeDatabase) ForgetBlock(ind int64) {
db.blkMtx.Lock()
defer db.blkMtx.Unlock()
delete(db.blockCache, ind)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"ForgetBlock",
"(",
"ind",
"int64",
")",
"{",
"db",
".",
"blkMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"blkMtx",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"db",
".",
"blockCache",
",",
... | // ForgetBlock deletes the block with the input height from the block cache. | [
"ForgetBlock",
"deletes",
"the",
"block",
"with",
"the",
"input",
"height",
"from",
"the",
"block",
"cache",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L480-L484 |
20,240 | decred/dcrdata | stakedb/stakedb.go | ConnectBlockHash | func (db *StakeDatabase) ConnectBlockHash(hash *chainhash.Hash) (*dcrutil.Block, error) {
msgBlock, err := db.NodeClient.GetBlock(hash)
if err != nil {
return nil, err
}
block := dcrutil.NewBlock(msgBlock)
return block, db.ConnectBlock(block)
} | go | func (db *StakeDatabase) ConnectBlockHash(hash *chainhash.Hash) (*dcrutil.Block, error) {
msgBlock, err := db.NodeClient.GetBlock(hash)
if err != nil {
return nil, err
}
block := dcrutil.NewBlock(msgBlock)
return block, db.ConnectBlock(block)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"ConnectBlockHash",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"msgBlock",
",",
"err",
":=",
"db",
".",
"NodeClient",
".",
"GetBlock",
"(",
... | // ConnectBlockHash is a wrapper for ConnectBlock. For the input block hash, it
// gets the block from the node RPC client and calls ConnectBlock. | [
"ConnectBlockHash",
"is",
"a",
"wrapper",
"for",
"ConnectBlock",
".",
"For",
"the",
"input",
"block",
"hash",
"it",
"gets",
"the",
"block",
"from",
"the",
"node",
"RPC",
"client",
"and",
"calls",
"ConnectBlock",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L488-L495 |
20,241 | decred/dcrdata | stakedb/stakedb.go | ConnectBlock | func (db *StakeDatabase) ConnectBlock(block *dcrutil.Block) error {
height := block.Height()
maturingHeight := height - int64(db.params.TicketMaturity)
var maturingTickets []chainhash.Hash
if maturingHeight >= 0 {
maturingBlock, wasCached := db.block(maturingHeight)
if wasCached {
db.ForgetBlock(maturingHei... | go | func (db *StakeDatabase) ConnectBlock(block *dcrutil.Block) error {
height := block.Height()
maturingHeight := height - int64(db.params.TicketMaturity)
var maturingTickets []chainhash.Hash
if maturingHeight >= 0 {
maturingBlock, wasCached := db.block(maturingHeight)
if wasCached {
db.ForgetBlock(maturingHei... | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"ConnectBlock",
"(",
"block",
"*",
"dcrutil",
".",
"Block",
")",
"error",
"{",
"height",
":=",
"block",
".",
"Height",
"(",
")",
"\n",
"maturingHeight",
":=",
"height",
"-",
"int64",
"(",
"db",
".",
"params... | // ConnectBlock connects the input block to the tip of the stake DB and updates
// the best stake node. This exported function gets any revoked and spend
// tickets from the input block, and any maturing tickets from the past block in
// which those tickets would be found, and passes them to connectBlock. | [
"ConnectBlock",
"connects",
"the",
"input",
"block",
"to",
"the",
"tip",
"of",
"the",
"stake",
"DB",
"and",
"updates",
"the",
"best",
"stake",
"node",
".",
"This",
"exported",
"function",
"gets",
"any",
"revoked",
"and",
"spend",
"tickets",
"from",
"the",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L501-L576 |
20,242 | decred/dcrdata | stakedb/stakedb.go | applyDiff | func (db *StakeDatabase) applyDiff(poolDiff PoolDiff) {
db.liveTicketMtx.Lock()
for _, hash := range poolDiff.In {
_, ok := db.liveTicketCache[hash]
if ok {
log.Warnf("Just tried to add a ticket (%v) to the pool, but it was already there!", hash)
continue
}
tx, err := db.NodeClient.GetRawTransaction(&h... | go | func (db *StakeDatabase) applyDiff(poolDiff PoolDiff) {
db.liveTicketMtx.Lock()
for _, hash := range poolDiff.In {
_, ok := db.liveTicketCache[hash]
if ok {
log.Warnf("Just tried to add a ticket (%v) to the pool, but it was already there!", hash)
continue
}
tx, err := db.NodeClient.GetRawTransaction(&h... | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"applyDiff",
"(",
"poolDiff",
"PoolDiff",
")",
"{",
"db",
".",
"liveTicketMtx",
".",
"Lock",
"(",
")",
"\n",
"for",
"_",
",",
"hash",
":=",
"range",
"poolDiff",
".",
"In",
"{",
"_",
",",
"ok",
":=",
"db... | // applyDiff updates liveTicketCache and poolValue for the given PoolDiff. | [
"applyDiff",
"updates",
"liveTicketCache",
"and",
"poolValue",
"for",
"the",
"given",
"PoolDiff",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L601-L632 |
20,243 | decred/dcrdata | stakedb/stakedb.go | undoDiff | func (db *StakeDatabase) undoDiff(poolDiff PoolDiff) {
db.applyDiff(PoolDiff{
In: poolDiff.Out,
Out: poolDiff.In,
})
} | go | func (db *StakeDatabase) undoDiff(poolDiff PoolDiff) {
db.applyDiff(PoolDiff{
In: poolDiff.Out,
Out: poolDiff.In,
})
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"undoDiff",
"(",
"poolDiff",
"PoolDiff",
")",
"{",
"db",
".",
"applyDiff",
"(",
"PoolDiff",
"{",
"In",
":",
"poolDiff",
".",
"Out",
",",
"Out",
":",
"poolDiff",
".",
"In",
",",
"}",
")",
"\n",
"}"
] | // undoDiff is like applyDiff except it swaps In and Out in the specified
// PoolDiff. | [
"undoDiff",
"is",
"like",
"applyDiff",
"except",
"it",
"swaps",
"In",
"and",
"Out",
"in",
"the",
"specified",
"PoolDiff",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L636-L641 |
20,244 | decred/dcrdata | stakedb/stakedb.go | SetPoolInfo | func (db *StakeDatabase) SetPoolInfo(blockHash chainhash.Hash, tpi *apitypes.TicketPoolInfo) {
db.poolInfo.Set(blockHash, tpi)
} | go | func (db *StakeDatabase) SetPoolInfo(blockHash chainhash.Hash, tpi *apitypes.TicketPoolInfo) {
db.poolInfo.Set(blockHash, tpi)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"SetPoolInfo",
"(",
"blockHash",
"chainhash",
".",
"Hash",
",",
"tpi",
"*",
"apitypes",
".",
"TicketPoolInfo",
")",
"{",
"db",
".",
"poolInfo",
".",
"Set",
"(",
"blockHash",
",",
"tpi",
")",
"\n",
"}"
] | // SetPoolInfo stores the ticket pool info for the given hash in the pool info
// cache. | [
"SetPoolInfo",
"stores",
"the",
"ticket",
"pool",
"info",
"for",
"the",
"given",
"hash",
"in",
"the",
"pool",
"info",
"cache",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L645-L647 |
20,245 | decred/dcrdata | stakedb/stakedb.go | SetPoolCacheCapacity | func (db *StakeDatabase) SetPoolCacheCapacity(cap int) error {
return db.poolInfo.SetCapacity(cap)
} | go | func (db *StakeDatabase) SetPoolCacheCapacity(cap int) error {
return db.poolInfo.SetCapacity(cap)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"SetPoolCacheCapacity",
"(",
"cap",
"int",
")",
"error",
"{",
"return",
"db",
".",
"poolInfo",
".",
"SetCapacity",
"(",
"cap",
")",
"\n",
"}"
] | // SetPoolCacheCapacity sets the pool info cache capacity to the specified
// number of elements. | [
"SetPoolCacheCapacity",
"sets",
"the",
"pool",
"info",
"cache",
"capacity",
"to",
"the",
"specified",
"number",
"of",
"elements",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L651-L653 |
20,246 | decred/dcrdata | stakedb/stakedb.go | DisconnectBlock | func (db *StakeDatabase) DisconnectBlock(neglectCache bool) error {
db.nodeMtx.Lock()
defer db.nodeMtx.Unlock()
return db.disconnectBlock(neglectCache)
} | go | func (db *StakeDatabase) DisconnectBlock(neglectCache bool) error {
db.nodeMtx.Lock()
defer db.nodeMtx.Unlock()
return db.disconnectBlock(neglectCache)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"DisconnectBlock",
"(",
"neglectCache",
"bool",
")",
"error",
"{",
"db",
".",
"nodeMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"nodeMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"db",
".",
"... | // DisconnectBlock attempts to disconnect the current best block from the stake
// DB and updates the best stake node. If the ticket pool db is advanced to the
// tip, it is trimmed, and the cache and pool value are updated. If neglectCache
// is true, the trim is performed, but cache and pool value are not updated.
//... | [
"DisconnectBlock",
"attempts",
"to",
"disconnect",
"the",
"current",
"best",
"block",
"from",
"the",
"stake",
"DB",
"and",
"updates",
"the",
"best",
"stake",
"node",
".",
"If",
"the",
"ticket",
"pool",
"db",
"is",
"advanced",
"to",
"the",
"tip",
"it",
"is"... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L660-L665 |
20,247 | decred/dcrdata | stakedb/stakedb.go | disconnectBlock | func (db *StakeDatabase) disconnectBlock(neglectCache bool) error {
childHeight := db.BestNode.Height()
parentBlock, err := db.dbPrevBlock()
if err != nil {
return err
}
if parentBlock.Height() != int64(childHeight)-1 {
panic("BestNode and stake DB are inconsistent")
}
// Trim the ticket pool db to the same... | go | func (db *StakeDatabase) disconnectBlock(neglectCache bool) error {
childHeight := db.BestNode.Height()
parentBlock, err := db.dbPrevBlock()
if err != nil {
return err
}
if parentBlock.Height() != int64(childHeight)-1 {
panic("BestNode and stake DB are inconsistent")
}
// Trim the ticket pool db to the same... | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"disconnectBlock",
"(",
"neglectCache",
"bool",
")",
"error",
"{",
"childHeight",
":=",
"db",
".",
"BestNode",
".",
"Height",
"(",
")",
"\n",
"parentBlock",
",",
"err",
":=",
"db",
".",
"dbPrevBlock",
"(",
")... | // disconnectBlock is the non-thread-safe version of DisconnectBlock. | [
"disconnectBlock",
"is",
"the",
"non",
"-",
"thread",
"-",
"safe",
"version",
"of",
"DisconnectBlock",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L668-L725 |
20,248 | decred/dcrdata | stakedb/stakedb.go | DisconnectBlocks | func (db *StakeDatabase) DisconnectBlocks(count int64) error {
db.nodeMtx.Lock()
defer db.nodeMtx.Unlock()
for i := int64(0); i < count; i++ {
if err := db.disconnectBlock(false); err != nil {
return err
}
}
return nil
} | go | func (db *StakeDatabase) DisconnectBlocks(count int64) error {
db.nodeMtx.Lock()
defer db.nodeMtx.Unlock()
for i := int64(0); i < count; i++ {
if err := db.disconnectBlock(false); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"DisconnectBlocks",
"(",
"count",
"int64",
")",
"error",
"{",
"db",
".",
"nodeMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"nodeMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"i",
":=",
"int64",
... | // DisconnectBlocks disconnects N blocks from the head of the chain. | [
"DisconnectBlocks",
"disconnects",
"N",
"blocks",
"from",
"the",
"head",
"of",
"the",
"chain",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L728-L739 |
20,249 | decred/dcrdata | stakedb/stakedb.go | Open | func (db *StakeDatabase) Open(dbName string) error {
db.nodeMtx.Lock()
defer db.nodeMtx.Unlock()
// Create a new database to store the accepted stake node data into.
var isFreshDB bool
var err error
db.StakeDB, err = database.Open(dbType, dbName, db.params.Net)
if err != nil {
if strings.Contains(err.Error(),... | go | func (db *StakeDatabase) Open(dbName string) error {
db.nodeMtx.Lock()
defer db.nodeMtx.Unlock()
// Create a new database to store the accepted stake node data into.
var isFreshDB bool
var err error
db.StakeDB, err = database.Open(dbType, dbName, db.params.Net)
if err != nil {
if strings.Contains(err.Error(),... | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"Open",
"(",
"dbName",
"string",
")",
"error",
"{",
"db",
".",
"nodeMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"nodeMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"// Create a new database to store the acce... | // Open attempts to open an existing stake database, and will create a new one
// if one does not exist. | [
"Open",
"attempts",
"to",
"open",
"an",
"existing",
"stake",
"database",
"and",
"will",
"create",
"a",
"new",
"one",
"if",
"one",
"does",
"not",
"exist",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L743-L809 |
20,250 | decred/dcrdata | stakedb/stakedb.go | Close | func (db *StakeDatabase) Close() error {
db.nodeMtx.Lock()
defer db.nodeMtx.Unlock()
err1 := db.PoolDB.Close()
err2 := db.StakeDB.Close()
if err1 == nil {
return err2
}
if err2 == nil {
return err1
}
return fmt.Errorf("%v + %v", err1, err2)
} | go | func (db *StakeDatabase) Close() error {
db.nodeMtx.Lock()
defer db.nodeMtx.Unlock()
err1 := db.PoolDB.Close()
err2 := db.StakeDB.Close()
if err1 == nil {
return err2
}
if err2 == nil {
return err1
}
return fmt.Errorf("%v + %v", err1, err2)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"Close",
"(",
")",
"error",
"{",
"db",
".",
"nodeMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"nodeMtx",
".",
"Unlock",
"(",
")",
"\n",
"err1",
":=",
"db",
".",
"PoolDB",
".",
"Close",
"(",
... | // Close will close the ticket pool and stake databases. | [
"Close",
"will",
"close",
"the",
"ticket",
"pool",
"and",
"stake",
"databases",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L812-L824 |
20,251 | decred/dcrdata | stakedb/stakedb.go | PoolInfoBest | func (db *StakeDatabase) PoolInfoBest() *apitypes.TicketPoolInfo {
db.nodeMtx.RLock()
if db.BestNode == nil {
db.nodeMtx.RUnlock()
log.Errorf("PoolInfoBest: BestNode is nil!")
return nil
}
poolSize := db.BestNode.PoolSize()
//liveTickets := db.BestNode.LiveTickets()
winningTickets := db.BestNode.Winners()
... | go | func (db *StakeDatabase) PoolInfoBest() *apitypes.TicketPoolInfo {
db.nodeMtx.RLock()
if db.BestNode == nil {
db.nodeMtx.RUnlock()
log.Errorf("PoolInfoBest: BestNode is nil!")
return nil
}
poolSize := db.BestNode.PoolSize()
//liveTickets := db.BestNode.LiveTickets()
winningTickets := db.BestNode.Winners()
... | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"PoolInfoBest",
"(",
")",
"*",
"apitypes",
".",
"TicketPoolInfo",
"{",
"db",
".",
"nodeMtx",
".",
"RLock",
"(",
")",
"\n",
"if",
"db",
".",
"BestNode",
"==",
"nil",
"{",
"db",
".",
"nodeMtx",
".",
"RUnloc... | // PoolInfoBest computes ticket pool value using the database and, if needed, the
// node RPC client to fetch ticket values that are not cached. Returned are a
// structure including ticket pool value, size, and average value. | [
"PoolInfoBest",
"computes",
"ticket",
"pool",
"value",
"using",
"the",
"database",
"and",
"if",
"needed",
"the",
"node",
"RPC",
"client",
"to",
"fetch",
"ticket",
"values",
"that",
"are",
"not",
"cached",
".",
"Returned",
"are",
"a",
"structure",
"including",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L852-L867 |
20,252 | decred/dcrdata | stakedb/stakedb.go | PoolInfo | func (db *StakeDatabase) PoolInfo(hash chainhash.Hash) (*apitypes.TicketPoolInfo, bool) {
return db.poolInfo.Get(hash)
} | go | func (db *StakeDatabase) PoolInfo(hash chainhash.Hash) (*apitypes.TicketPoolInfo, bool) {
return db.poolInfo.Get(hash)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"PoolInfo",
"(",
"hash",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"apitypes",
".",
"TicketPoolInfo",
",",
"bool",
")",
"{",
"return",
"db",
".",
"poolInfo",
".",
"Get",
"(",
"hash",
")",
"\n",
"}"
] | // PoolInfo attempts to fetch the ticket pool info for the specified block hash
// from an internal pool info cache. If it is not found, you should attempt to
// use PoolInfoBest if the target block is at the tip of the chain. | [
"PoolInfo",
"attempts",
"to",
"fetch",
"the",
"ticket",
"pool",
"info",
"for",
"the",
"specified",
"block",
"hash",
"from",
"an",
"internal",
"pool",
"info",
"cache",
".",
"If",
"it",
"is",
"not",
"found",
"you",
"should",
"attempt",
"to",
"use",
"PoolInfo... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L935-L937 |
20,253 | decred/dcrdata | stakedb/stakedb.go | PoolSize | func (db *StakeDatabase) PoolSize() int {
db.nodeMtx.Lock()
defer db.nodeMtx.Unlock()
return db.BestNode.PoolSize()
} | go | func (db *StakeDatabase) PoolSize() int {
db.nodeMtx.Lock()
defer db.nodeMtx.Unlock()
return db.BestNode.PoolSize()
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"PoolSize",
"(",
")",
"int",
"{",
"db",
".",
"nodeMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"nodeMtx",
".",
"Unlock",
"(",
")",
"\n",
"return",
"db",
".",
"BestNode",
".",
"PoolSize",
"(",
... | // PoolSize returns the ticket pool size in the best node of the stake database | [
"PoolSize",
"returns",
"the",
"ticket",
"pool",
"size",
"in",
"the",
"best",
"node",
"of",
"the",
"stake",
"database"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L940-L944 |
20,254 | decred/dcrdata | stakedb/stakedb.go | PoolAtHeight | func (db *StakeDatabase) PoolAtHeight(height int64) ([]chainhash.Hash, error) {
return db.PoolDB.Pool(height)
} | go | func (db *StakeDatabase) PoolAtHeight(height int64) ([]chainhash.Hash, error) {
return db.PoolDB.Pool(height)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"PoolAtHeight",
"(",
"height",
"int64",
")",
"(",
"[",
"]",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"return",
"db",
".",
"PoolDB",
".",
"Pool",
"(",
"height",
")",
"\n",
"}"
] | // PoolAtHeight gets the entire list of live tickets at the given chain height. | [
"PoolAtHeight",
"gets",
"the",
"entire",
"list",
"of",
"live",
"tickets",
"at",
"the",
"given",
"chain",
"height",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L947-L949 |
20,255 | decred/dcrdata | stakedb/stakedb.go | PoolAtHash | func (db *StakeDatabase) PoolAtHash(hash chainhash.Hash) ([]chainhash.Hash, error) {
header, err := db.NodeClient.GetBlockHeader(&hash)
if err != nil {
return nil, fmt.Errorf("GetBlockHeader failed: %v", err)
}
return db.PoolDB.Pool(int64(header.Height))
} | go | func (db *StakeDatabase) PoolAtHash(hash chainhash.Hash) ([]chainhash.Hash, error) {
header, err := db.NodeClient.GetBlockHeader(&hash)
if err != nil {
return nil, fmt.Errorf("GetBlockHeader failed: %v", err)
}
return db.PoolDB.Pool(int64(header.Height))
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"PoolAtHash",
"(",
"hash",
"chainhash",
".",
"Hash",
")",
"(",
"[",
"]",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"header",
",",
"err",
":=",
"db",
".",
"NodeClient",
".",
"GetBlockHeader",
"(",
... | // PoolAtHash gets the entire list of live tickets at the given block hash. | [
"PoolAtHash",
"gets",
"the",
"entire",
"list",
"of",
"live",
"tickets",
"at",
"the",
"given",
"block",
"hash",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L952-L958 |
20,256 | decred/dcrdata | stakedb/stakedb.go | DBState | func (db *StakeDatabase) DBState() (uint32, *chainhash.Hash, error) {
db.nodeMtx.RLock()
defer db.nodeMtx.RUnlock()
return db.dbState()
} | go | func (db *StakeDatabase) DBState() (uint32, *chainhash.Hash, error) {
db.nodeMtx.RLock()
defer db.nodeMtx.RUnlock()
return db.dbState()
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"DBState",
"(",
")",
"(",
"uint32",
",",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"db",
".",
"nodeMtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"db",
".",
"nodeMtx",
".",
"RUnlock",
"(",
... | // DBState queries the stake database for the best block height and hash. | [
"DBState",
"queries",
"the",
"stake",
"database",
"for",
"the",
"best",
"block",
"height",
"and",
"hash",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L961-L966 |
20,257 | decred/dcrdata | stakedb/stakedb.go | DBTipBlockHeader | func (db *StakeDatabase) DBTipBlockHeader() (*wire.BlockHeader, error) {
_, hash, err := db.DBState()
if err != nil {
return nil, err
}
return db.NodeClient.GetBlockHeader(hash)
} | go | func (db *StakeDatabase) DBTipBlockHeader() (*wire.BlockHeader, error) {
_, hash, err := db.DBState()
if err != nil {
return nil, err
}
return db.NodeClient.GetBlockHeader(hash)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"DBTipBlockHeader",
"(",
")",
"(",
"*",
"wire",
".",
"BlockHeader",
",",
"error",
")",
"{",
"_",
",",
"hash",
",",
"err",
":=",
"db",
".",
"DBState",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"re... | // DBTipBlockHeader gets the block header for the current best block in the
// stake database. It used DBState to get the best block hash, and the node RPC
// client to get the header. | [
"DBTipBlockHeader",
"gets",
"the",
"block",
"header",
"for",
"the",
"current",
"best",
"block",
"in",
"the",
"stake",
"database",
".",
"It",
"used",
"DBState",
"to",
"get",
"the",
"best",
"block",
"hash",
"and",
"the",
"node",
"RPC",
"client",
"to",
"get",... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L989-L996 |
20,258 | decred/dcrdata | stakedb/stakedb.go | DBPrevBlockHeader | func (db *StakeDatabase) DBPrevBlockHeader() (*wire.BlockHeader, error) {
_, hash, err := db.DBState()
if err != nil {
return nil, err
}
parentHeader, err := db.NodeClient.GetBlockHeader(hash)
if err != nil {
return nil, err
}
return db.NodeClient.GetBlockHeader(&parentHeader.PrevBlock)
} | go | func (db *StakeDatabase) DBPrevBlockHeader() (*wire.BlockHeader, error) {
_, hash, err := db.DBState()
if err != nil {
return nil, err
}
parentHeader, err := db.NodeClient.GetBlockHeader(hash)
if err != nil {
return nil, err
}
return db.NodeClient.GetBlockHeader(&parentHeader.PrevBlock)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"DBPrevBlockHeader",
"(",
")",
"(",
"*",
"wire",
".",
"BlockHeader",
",",
"error",
")",
"{",
"_",
",",
"hash",
",",
"err",
":=",
"db",
".",
"DBState",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // DBPrevBlockHeader gets the block header for the previous best block in the
// stake database. It used DBState to get the best block hash, and the node RPC
// client to get the header. | [
"DBPrevBlockHeader",
"gets",
"the",
"block",
"header",
"for",
"the",
"previous",
"best",
"block",
"in",
"the",
"stake",
"database",
".",
"It",
"used",
"DBState",
"to",
"get",
"the",
"best",
"block",
"hash",
"and",
"the",
"node",
"RPC",
"client",
"to",
"get... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L1001-L1013 |
20,259 | decred/dcrdata | stakedb/stakedb.go | DBTipBlock | func (db *StakeDatabase) DBTipBlock() (*dcrutil.Block, error) {
_, hash, err := db.DBState()
if err != nil {
return nil, err
}
return db.getBlock(hash)
} | go | func (db *StakeDatabase) DBTipBlock() (*dcrutil.Block, error) {
_, hash, err := db.DBState()
if err != nil {
return nil, err
}
return db.getBlock(hash)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"DBTipBlock",
"(",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"_",
",",
"hash",
",",
"err",
":=",
"db",
".",
"DBState",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // DBTipBlock gets the dcrutil.Block for the current best block in the stake
// database. It used DBState to get the best block hash, and the node RPC client
// to get the block itself. | [
"DBTipBlock",
"gets",
"the",
"dcrutil",
".",
"Block",
"for",
"the",
"current",
"best",
"block",
"in",
"the",
"stake",
"database",
".",
"It",
"used",
"DBState",
"to",
"get",
"the",
"best",
"block",
"hash",
"and",
"the",
"node",
"RPC",
"client",
"to",
"get... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L1018-L1025 |
20,260 | decred/dcrdata | stakedb/stakedb.go | DBPrevBlock | func (db *StakeDatabase) DBPrevBlock() (*dcrutil.Block, error) {
_, hash, err := db.DBState()
if err != nil {
return nil, err
}
parentHeader, err := db.NodeClient.GetBlockHeader(hash)
if err != nil {
return nil, err
}
return db.getBlock(&parentHeader.PrevBlock)
} | go | func (db *StakeDatabase) DBPrevBlock() (*dcrutil.Block, error) {
_, hash, err := db.DBState()
if err != nil {
return nil, err
}
parentHeader, err := db.NodeClient.GetBlockHeader(hash)
if err != nil {
return nil, err
}
return db.getBlock(&parentHeader.PrevBlock)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"DBPrevBlock",
"(",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"_",
",",
"hash",
",",
"err",
":=",
"db",
".",
"DBState",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // DBPrevBlock gets the dcrutil.Block for the previous best block in the stake
// database. It used DBState to get the best block hash, and the node RPC client
// to get the block itself. | [
"DBPrevBlock",
"gets",
"the",
"dcrutil",
".",
"Block",
"for",
"the",
"previous",
"best",
"block",
"in",
"the",
"stake",
"database",
".",
"It",
"used",
"DBState",
"to",
"get",
"the",
"best",
"block",
"hash",
"and",
"the",
"node",
"RPC",
"client",
"to",
"g... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L1030-L1042 |
20,261 | decred/dcrdata | stakedb/stakedb.go | dbPrevBlock | func (db *StakeDatabase) dbPrevBlock() (*dcrutil.Block, error) {
_, hash, err := db.dbState()
if err != nil {
return nil, err
}
parentHeader, err := db.NodeClient.GetBlockHeader(hash)
if err != nil {
return nil, err
}
return db.getBlock(&parentHeader.PrevBlock)
} | go | func (db *StakeDatabase) dbPrevBlock() (*dcrutil.Block, error) {
_, hash, err := db.dbState()
if err != nil {
return nil, err
}
parentHeader, err := db.NodeClient.GetBlockHeader(hash)
if err != nil {
return nil, err
}
return db.getBlock(&parentHeader.PrevBlock)
} | [
"func",
"(",
"db",
"*",
"StakeDatabase",
")",
"dbPrevBlock",
"(",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"_",
",",
"hash",
",",
"err",
":=",
"db",
".",
"dbState",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // dbPrevBlock is the non-thread-safe version of DBPrevBlock. | [
"dbPrevBlock",
"is",
"the",
"non",
"-",
"thread",
"-",
"safe",
"version",
"of",
"DBPrevBlock",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/stakedb.go#L1045-L1057 |
20,262 | decred/dcrdata | rpcutils/blockgate.go | NewBlockGate | func NewBlockGate(client BlockFetcher, capacity int) *BlockGate {
return &BlockGate{
client: client,
height: -1,
fetchToHeight: -1,
hashAtHeight: make(map[int64]chainhash.Hash),
blockWithHash: make(map[chainhash.Hash]*dcrutil.Block),
heightWaiters: make(map[int64][]chan chainhash.Hash),
ha... | go | func NewBlockGate(client BlockFetcher, capacity int) *BlockGate {
return &BlockGate{
client: client,
height: -1,
fetchToHeight: -1,
hashAtHeight: make(map[int64]chainhash.Hash),
blockWithHash: make(map[chainhash.Hash]*dcrutil.Block),
heightWaiters: make(map[int64][]chan chainhash.Hash),
ha... | [
"func",
"NewBlockGate",
"(",
"client",
"BlockFetcher",
",",
"capacity",
"int",
")",
"*",
"BlockGate",
"{",
"return",
"&",
"BlockGate",
"{",
"client",
":",
"client",
",",
"height",
":",
"-",
"1",
",",
"fetchToHeight",
":",
"-",
"1",
",",
"hashAtHeight",
"... | // NewBlockGate constructs a new BlockGate, wrapping an RPC client, with a
// specified block cache capacity. | [
"NewBlockGate",
"constructs",
"a",
"new",
"BlockGate",
"wrapping",
"an",
"RPC",
"client",
"with",
"a",
"specified",
"block",
"cache",
"capacity",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L83-L96 |
20,263 | decred/dcrdata | rpcutils/blockgate.go | SetFetchToHeight | func (g *BlockGate) SetFetchToHeight(height int64) {
g.mtx.RLock()
defer g.mtx.RUnlock()
g.fetchToHeight = height
} | go | func (g *BlockGate) SetFetchToHeight(height int64) {
g.mtx.RLock()
defer g.mtx.RUnlock()
g.fetchToHeight = height
} | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"SetFetchToHeight",
"(",
"height",
"int64",
")",
"{",
"g",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"g",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"g",
".",
"fetchToHeight",
"=",
"height",
"\n",
... | // SetFetchToHeight sets the height up to which WaitForHeight will trigger an
// RPC to retrieve the block immediately. For the given height and up,
// WaitForHeight will only return a notification channel. | [
"SetFetchToHeight",
"sets",
"the",
"height",
"up",
"to",
"which",
"WaitForHeight",
"will",
"trigger",
"an",
"RPC",
"to",
"retrieve",
"the",
"block",
"immediately",
".",
"For",
"the",
"given",
"height",
"and",
"up",
"WaitForHeight",
"will",
"only",
"return",
"a... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L101-L105 |
20,264 | decred/dcrdata | rpcutils/blockgate.go | NodeHeight | func (g *BlockGate) NodeHeight() (int64, error) {
_, height, err := g.client.GetBestBlock()
return height, err
} | go | func (g *BlockGate) NodeHeight() (int64, error) {
_, height, err := g.client.GetBestBlock()
return height, err
} | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"NodeHeight",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"_",
",",
"height",
",",
"err",
":=",
"g",
".",
"client",
".",
"GetBestBlock",
"(",
")",
"\n",
"return",
"height",
",",
"err",
"\n",
"}"
] | // NodeHeight gets the chain height from dcrd. | [
"NodeHeight",
"gets",
"the",
"chain",
"height",
"from",
"dcrd",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L108-L111 |
20,265 | decred/dcrdata | rpcutils/blockgate.go | BestBlockHeight | func (g *BlockGate) BestBlockHeight() int64 {
g.mtx.RLock()
defer g.mtx.RUnlock()
return g.height
} | go | func (g *BlockGate) BestBlockHeight() int64 {
g.mtx.RLock()
defer g.mtx.RUnlock()
return g.height
} | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"BestBlockHeight",
"(",
")",
"int64",
"{",
"g",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"g",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"g",
".",
"height",
"\n",
"}"
] | // BestBlockHeight gets the best block height in the block cache. | [
"BestBlockHeight",
"gets",
"the",
"best",
"block",
"height",
"in",
"the",
"block",
"cache",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L114-L118 |
20,266 | decred/dcrdata | rpcutils/blockgate.go | BestBlockHash | func (g *BlockGate) BestBlockHash() (chainhash.Hash, int64, error) {
g.mtx.RLock()
defer g.mtx.RUnlock()
var err error
hash, ok := g.hashAtHeight[g.height]
if !ok {
err = fmt.Errorf("hash of best block %d not found", g.height)
}
return hash, g.height, err
} | go | func (g *BlockGate) BestBlockHash() (chainhash.Hash, int64, error) {
g.mtx.RLock()
defer g.mtx.RUnlock()
var err error
hash, ok := g.hashAtHeight[g.height]
if !ok {
err = fmt.Errorf("hash of best block %d not found", g.height)
}
return hash, g.height, err
} | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"BestBlockHash",
"(",
")",
"(",
"chainhash",
".",
"Hash",
",",
"int64",
",",
"error",
")",
"{",
"g",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"g",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"v... | // BestBlockHash gets the hash and height of the best block in cache. | [
"BestBlockHash",
"gets",
"the",
"hash",
"and",
"height",
"of",
"the",
"best",
"block",
"in",
"cache",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L121-L130 |
20,267 | decred/dcrdata | rpcutils/blockgate.go | BestBlock | func (g *BlockGate) BestBlock() (*dcrutil.Block, error) {
g.mtx.RLock()
defer g.mtx.RUnlock()
var err error
hash, ok := g.hashAtHeight[g.height]
if !ok {
err = fmt.Errorf("hash of best block %d not found", g.height)
}
block, ok := g.blockWithHash[hash]
if !ok {
err = fmt.Errorf("block %d at height %d not fo... | go | func (g *BlockGate) BestBlock() (*dcrutil.Block, error) {
g.mtx.RLock()
defer g.mtx.RUnlock()
var err error
hash, ok := g.hashAtHeight[g.height]
if !ok {
err = fmt.Errorf("hash of best block %d not found", g.height)
}
block, ok := g.blockWithHash[hash]
if !ok {
err = fmt.Errorf("block %d at height %d not fo... | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"BestBlock",
"(",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"g",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"g",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"var",
"err",
... | // BestBlock gets the best block in cache. | [
"BestBlock",
"gets",
"the",
"best",
"block",
"in",
"cache",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L133-L146 |
20,268 | decred/dcrdata | rpcutils/blockgate.go | CachedBlock | func (g *BlockGate) CachedBlock(hash chainhash.Hash) (*dcrutil.Block, error) {
g.mtx.RLock()
defer g.mtx.RUnlock()
block, ok := g.blockWithHash[hash]
if !ok {
return nil, fmt.Errorf("block %d not found", hash)
}
return block, nil
} | go | func (g *BlockGate) CachedBlock(hash chainhash.Hash) (*dcrutil.Block, error) {
g.mtx.RLock()
defer g.mtx.RUnlock()
block, ok := g.blockWithHash[hash]
if !ok {
return nil, fmt.Errorf("block %d not found", hash)
}
return block, nil
} | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"CachedBlock",
"(",
"hash",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"g",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"g",
".",
"mtx",
".",
"RUnlock"... | // CachedBlock attempts to get the block with the specified hash from cache. | [
"CachedBlock",
"attempts",
"to",
"get",
"the",
"block",
"with",
"the",
"specified",
"hash",
"from",
"cache",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L149-L157 |
20,269 | decred/dcrdata | rpcutils/blockgate.go | Block | func (g *BlockGate) Block(hash chainhash.Hash) (*dcrutil.Block, error) {
// Try block cache first.
block, err := g.CachedBlock(hash)
if err == nil {
return block, nil
}
// Cache miss. Retrieve from dcrd RPC.
block, err = GetBlockByHash(&hash, g.client)
if err != nil {
return nil, fmt.Errorf("GetBlock (%v) f... | go | func (g *BlockGate) Block(hash chainhash.Hash) (*dcrutil.Block, error) {
// Try block cache first.
block, err := g.CachedBlock(hash)
if err == nil {
return block, nil
}
// Cache miss. Retrieve from dcrd RPC.
block, err = GetBlockByHash(&hash, g.client)
if err != nil {
return nil, fmt.Errorf("GetBlock (%v) f... | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"Block",
"(",
"hash",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"// Try block cache first.",
"block",
",",
"err",
":=",
"g",
".",
"CachedBlock",
"(",
"hash",
")",
... | // Block first attempts to get the block with the specified hash from cache. In
// the event of a cache miss, the block is retrieved from dcrd via RPC. | [
"Block",
"first",
"attempts",
"to",
"get",
"the",
"block",
"with",
"the",
"specified",
"hash",
"from",
"cache",
".",
"In",
"the",
"event",
"of",
"a",
"cache",
"miss",
"the",
"block",
"is",
"retrieved",
"from",
"dcrd",
"via",
"RPC",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L161-L179 |
20,270 | decred/dcrdata | rpcutils/blockgate.go | UpdateToBestBlock | func (g *BlockGate) UpdateToBestBlock() (*dcrutil.Block, error) {
_, height, err := g.client.GetBestBlock()
if err != nil {
return nil, fmt.Errorf("GetBestBlockHash failed: %v", err)
}
return g.UpdateToBlock(height)
} | go | func (g *BlockGate) UpdateToBestBlock() (*dcrutil.Block, error) {
_, height, err := g.client.GetBestBlock()
if err != nil {
return nil, fmt.Errorf("GetBestBlockHash failed: %v", err)
}
return g.UpdateToBlock(height)
} | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"UpdateToBestBlock",
"(",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"_",
",",
"height",
",",
"err",
":=",
"g",
".",
"client",
".",
"GetBestBlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"... | // UpdateToBestBlock gets the best block via RPC and updates the cache. | [
"UpdateToBestBlock",
"gets",
"the",
"best",
"block",
"via",
"RPC",
"and",
"updates",
"the",
"cache",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L182-L189 |
20,271 | decred/dcrdata | rpcutils/blockgate.go | UpdateToNextBlock | func (g *BlockGate) UpdateToNextBlock() (*dcrutil.Block, error) {
g.mtx.Lock()
height := g.height + 1
g.mtx.Unlock()
return g.UpdateToBlock(height)
} | go | func (g *BlockGate) UpdateToNextBlock() (*dcrutil.Block, error) {
g.mtx.Lock()
height := g.height + 1
g.mtx.Unlock()
return g.UpdateToBlock(height)
} | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"UpdateToNextBlock",
"(",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"g",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"height",
":=",
"g",
".",
"height",
"+",
"1",
"\n",
"g",
".",
"mtx"... | // UpdateToNextBlock gets the next block following the best in cache via RPC and
// updates the cache. | [
"UpdateToNextBlock",
"gets",
"the",
"next",
"block",
"following",
"the",
"best",
"in",
"cache",
"via",
"RPC",
"and",
"updates",
"the",
"cache",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L193-L198 |
20,272 | decred/dcrdata | rpcutils/blockgate.go | UpdateToBlock | func (g *BlockGate) UpdateToBlock(height int64) (*dcrutil.Block, error) {
g.mtx.Lock()
defer g.mtx.Unlock()
return g.updateToBlock(height)
} | go | func (g *BlockGate) UpdateToBlock(height int64) (*dcrutil.Block, error) {
g.mtx.Lock()
defer g.mtx.Unlock()
return g.updateToBlock(height)
} | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"UpdateToBlock",
"(",
"height",
"int64",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"g",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"g",
".",
"mtx",
".",
"Unlock",
"(",
")",
"... | // UpdateToBlock gets the block at the specified height on the main chain from
// dcrd, stores it in cache, and signals any waiters. This is the thread-safe
// version of updateToBlock. | [
"UpdateToBlock",
"gets",
"the",
"block",
"at",
"the",
"specified",
"height",
"on",
"the",
"main",
"chain",
"from",
"dcrd",
"stores",
"it",
"in",
"cache",
"and",
"signals",
"any",
"waiters",
".",
"This",
"is",
"the",
"thread",
"-",
"safe",
"version",
"of",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L203-L207 |
20,273 | decred/dcrdata | rpcutils/blockgate.go | updateToBlock | func (g *BlockGate) updateToBlock(height int64) (*dcrutil.Block, error) {
block, hash, err := GetBlock(height, g.client)
if err != nil {
return nil, fmt.Errorf("GetBlock (%d) failed: %v", height, err)
}
if block.Height() != height {
return nil, fmt.Errorf("GetBlock (%d) returned block at height %d",
height,... | go | func (g *BlockGate) updateToBlock(height int64) (*dcrutil.Block, error) {
block, hash, err := GetBlock(height, g.client)
if err != nil {
return nil, fmt.Errorf("GetBlock (%d) failed: %v", height, err)
}
if block.Height() != height {
return nil, fmt.Errorf("GetBlock (%d) returned block at height %d",
height,... | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"updateToBlock",
"(",
"height",
"int64",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"block",
",",
"hash",
",",
"err",
":=",
"GetBlock",
"(",
"height",
",",
"g",
".",
"client",
")",
"\n",... | // updateToBlock gets the block at the specified height on the main chain from
// dcrd. It is not thread-safe. It wrapped by UpdateToBlock for thread-safety,
// and used directly by WaitForHeight which locks the BlockGate. | [
"updateToBlock",
"gets",
"the",
"block",
"at",
"the",
"specified",
"height",
"on",
"the",
"main",
"chain",
"from",
"dcrd",
".",
"It",
"is",
"not",
"thread",
"-",
"safe",
".",
"It",
"wrapped",
"by",
"UpdateToBlock",
"for",
"thread",
"-",
"safety",
"and",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L212-L240 |
20,274 | decred/dcrdata | rpcutils/blockgate.go | WaitForHeight | func (g *BlockGate) WaitForHeight(height int64) chan chainhash.Hash {
g.mtx.Lock()
defer g.mtx.Unlock()
if height < 0 {
return nil
}
waitChan := make(chan chainhash.Hash, 1)
// Queue for future send.
g.heightWaiters[height] = append(g.heightWaiters[height], waitChan)
// If the block is already cached, send... | go | func (g *BlockGate) WaitForHeight(height int64) chan chainhash.Hash {
g.mtx.Lock()
defer g.mtx.Unlock()
if height < 0 {
return nil
}
waitChan := make(chan chainhash.Hash, 1)
// Queue for future send.
g.heightWaiters[height] = append(g.heightWaiters[height], waitChan)
// If the block is already cached, send... | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"WaitForHeight",
"(",
"height",
"int64",
")",
"chan",
"chainhash",
".",
"Hash",
"{",
"g",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"g",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"height",
... | // WaitForHeight provides a notification channel for signaling to the caller
// when the block at the specified height is available. | [
"WaitForHeight",
"provides",
"a",
"notification",
"channel",
"for",
"signaling",
"to",
"the",
"caller",
"when",
"the",
"block",
"at",
"the",
"specified",
"height",
"is",
"available",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L324-L351 |
20,275 | decred/dcrdata | rpcutils/blockgate.go | WaitForHash | func (g *BlockGate) WaitForHash(hash chainhash.Hash) chan int64 {
g.mtx.Lock()
defer g.mtx.Unlock()
waitChan := make(chan int64, 1)
// Queue for future send.
g.hashWaiters[hash] = append(g.hashWaiters[hash], waitChan)
// If the block is already cached, send now.
if block, ok := g.blockWithHash[hash]; ok {
g... | go | func (g *BlockGate) WaitForHash(hash chainhash.Hash) chan int64 {
g.mtx.Lock()
defer g.mtx.Unlock()
waitChan := make(chan int64, 1)
// Queue for future send.
g.hashWaiters[hash] = append(g.hashWaiters[hash], waitChan)
// If the block is already cached, send now.
if block, ok := g.blockWithHash[hash]; ok {
g... | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"WaitForHash",
"(",
"hash",
"chainhash",
".",
"Hash",
")",
"chan",
"int64",
"{",
"g",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"g",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"waitChan",
":=",
"... | // WaitForHash provides a notification channel for signaling to the caller
// when the block with the specified hash is available. | [
"WaitForHash",
"provides",
"a",
"notification",
"channel",
"for",
"signaling",
"to",
"the",
"caller",
"when",
"the",
"block",
"with",
"the",
"specified",
"hash",
"is",
"available",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L355-L370 |
20,276 | decred/dcrdata | rpcutils/blockgate.go | GetChainWork | func (g *BlockGate) GetChainWork(hash *chainhash.Hash) (string, error) {
return GetChainWork(g.client, hash)
} | go | func (g *BlockGate) GetChainWork(hash *chainhash.Hash) (string, error) {
return GetChainWork(g.client, hash)
} | [
"func",
"(",
"g",
"*",
"BlockGate",
")",
"GetChainWork",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"GetChainWork",
"(",
"g",
".",
"client",
",",
"hash",
")",
"\n",
"}"
] | // GetChainWork fetches the dcrjson.BlockHeaderVerbose and returns only the
// ChainWork attribute as a string. | [
"GetChainWork",
"fetches",
"the",
"dcrjson",
".",
"BlockHeaderVerbose",
"and",
"returns",
"only",
"the",
"ChainWork",
"attribute",
"as",
"a",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/blockgate.go#L374-L376 |
20,277 | decred/dcrdata | stakedb/ticketpool.go | Infof | func (l *badgerLogger) Infof(format string, v ...interface{}) {
l.logf(logLevelInfo, format, v...)
} | go | func (l *badgerLogger) Infof(format string, v ...interface{}) {
l.logf(logLevelInfo, format, v...)
} | [
"func",
"(",
"l",
"*",
"badgerLogger",
")",
"Infof",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"logf",
"(",
"logLevelInfo",
",",
"format",
",",
"v",
"...",
")",
"\n",
"}"
] | // Infof filters messages through logf with logLevelInfo before sending the
// message to the slog.Logger. | [
"Infof",
"filters",
"messages",
"through",
"logf",
"with",
"logLevelInfo",
"before",
"sending",
"the",
"message",
"to",
"the",
"slog",
".",
"Logger",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L118-L120 |
20,278 | decred/dcrdata | stakedb/ticketpool.go | Warningf | func (l *badgerLogger) Warningf(format string, v ...interface{}) {
l.logf(logLevelWarn, format, v...)
} | go | func (l *badgerLogger) Warningf(format string, v ...interface{}) {
l.logf(logLevelWarn, format, v...)
} | [
"func",
"(",
"l",
"*",
"badgerLogger",
")",
"Warningf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"logf",
"(",
"logLevelWarn",
",",
"format",
",",
"v",
"...",
")",
"\n",
"}"
] | // Warningf filters messages through logf with logLevelWarn before sending the
// message to the slog.Logger. | [
"Warningf",
"filters",
"messages",
"through",
"logf",
"with",
"logLevelWarn",
"before",
"sending",
"the",
"message",
"to",
"the",
"slog",
".",
"Logger",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L124-L126 |
20,279 | decred/dcrdata | stakedb/ticketpool.go | Errorf | func (l *badgerLogger) Errorf(format string, v ...interface{}) {
l.logf(logLevelError, format, v...)
} | go | func (l *badgerLogger) Errorf(format string, v ...interface{}) {
l.logf(logLevelError, format, v...)
} | [
"func",
"(",
"l",
"*",
"badgerLogger",
")",
"Errorf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"logf",
"(",
"logLevelError",
",",
"format",
",",
"v",
"...",
")",
"\n",
"}"
] | // Errorf filters messages through logf with logLevelError before sending the
// message to the slog.Logger. | [
"Errorf",
"filters",
"messages",
"through",
"logf",
"with",
"logLevelError",
"before",
"sending",
"the",
"message",
"to",
"the",
"slog",
".",
"Logger",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L130-L132 |
20,280 | decred/dcrdata | stakedb/ticketpool.go | NewTicketPool | func NewTicketPool(dataDir, dbSubDir string) (tp *TicketPool, err error) {
// Open ticket pool diffs database
badgerDbPath := filepath.Join(dataDir, dbSubDir)
opts := badger.DefaultOptions
opts.Dir = badgerDbPath
opts.ValueDir = badgerDbPath
opts.Logger = &badgerLogger{log}
db, err := badger.Open(opts)
if err =... | go | func NewTicketPool(dataDir, dbSubDir string) (tp *TicketPool, err error) {
// Open ticket pool diffs database
badgerDbPath := filepath.Join(dataDir, dbSubDir)
opts := badger.DefaultOptions
opts.Dir = badgerDbPath
opts.ValueDir = badgerDbPath
opts.Logger = &badgerLogger{log}
db, err := badger.Open(opts)
if err =... | [
"func",
"NewTicketPool",
"(",
"dataDir",
",",
"dbSubDir",
"string",
")",
"(",
"tp",
"*",
"TicketPool",
",",
"err",
"error",
")",
"{",
"// Open ticket pool diffs database",
"badgerDbPath",
":=",
"filepath",
".",
"Join",
"(",
"dataDir",
",",
"dbSubDir",
")",
"\n... | // NewTicketPool constructs a TicketPool by opening the persistent diff db,
// loading all known diffs, initializing the TicketPool values. | [
"NewTicketPool",
"constructs",
"a",
"TicketPool",
"by",
"opening",
"the",
"persistent",
"diff",
"db",
"loading",
"all",
"known",
"diffs",
"initializing",
"the",
"TicketPool",
"values",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L136-L209 |
20,281 | decred/dcrdata | stakedb/ticketpool.go | MigrateFromStorm | func MigrateFromStorm(stormDBFile string, db *badger.DB) (bool, error) {
// Check for the storm DB file
finfo, err := os.Stat(stormDBFile)
if os.IsNotExist(err) {
return false, nil
}
if err != nil {
return false, err
}
if finfo.Size() == 0 {
return false, nil
}
// Open the storm DB file
dbOld, err := s... | go | func MigrateFromStorm(stormDBFile string, db *badger.DB) (bool, error) {
// Check for the storm DB file
finfo, err := os.Stat(stormDBFile)
if os.IsNotExist(err) {
return false, nil
}
if err != nil {
return false, err
}
if finfo.Size() == 0 {
return false, nil
}
// Open the storm DB file
dbOld, err := s... | [
"func",
"MigrateFromStorm",
"(",
"stormDBFile",
"string",
",",
"db",
"*",
"badger",
".",
"DB",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// Check for the storm DB file",
"finfo",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"stormDBFile",
")",
"\n",
"if",
... | // MigrateFromStorm attempts to load the storm DB specified by the given file
// name, and migrate all ticket pool diffs to the badger db. | [
"MigrateFromStorm",
"attempts",
"to",
"load",
"the",
"storm",
"DB",
"specified",
"by",
"the",
"given",
"file",
"name",
"and",
"migrate",
"all",
"ticket",
"pool",
"diffs",
"to",
"the",
"badger",
"db",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L213-L270 |
20,282 | decred/dcrdata | stakedb/ticketpool.go | LoadAllPoolDiffs | func LoadAllPoolDiffs(db *badger.DB) ([]PoolDiff, error) {
var poolDiffs []PoolDiff
err := db.View(func(txn *badger.Txn) error {
// Create the badger iterator
opts := badger.IteratorOptions{
PrefetchValues: true,
PrefetchSize: 1000,
Reverse: false,
AllVersions: false,
}
it := txn.NewIt... | go | func LoadAllPoolDiffs(db *badger.DB) ([]PoolDiff, error) {
var poolDiffs []PoolDiff
err := db.View(func(txn *badger.Txn) error {
// Create the badger iterator
opts := badger.IteratorOptions{
PrefetchValues: true,
PrefetchSize: 1000,
Reverse: false,
AllVersions: false,
}
it := txn.NewIt... | [
"func",
"LoadAllPoolDiffs",
"(",
"db",
"*",
"badger",
".",
"DB",
")",
"(",
"[",
"]",
"PoolDiff",
",",
"error",
")",
"{",
"var",
"poolDiffs",
"[",
"]",
"PoolDiff",
"\n",
"err",
":=",
"db",
".",
"View",
"(",
"func",
"(",
"txn",
"*",
"badger",
".",
... | // LoadAllPoolDiffs loads all found ticket pool diffs from badger DB. | [
"LoadAllPoolDiffs",
"loads",
"all",
"found",
"ticket",
"pool",
"diffs",
"from",
"badger",
"DB",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L273-L327 |
20,283 | decred/dcrdata | stakedb/ticketpool.go | Tip | func (tp *TicketPool) Tip() int64 {
tp.mtx.RLock()
defer tp.mtx.RUnlock()
return tp.tip
} | go | func (tp *TicketPool) Tip() int64 {
tp.mtx.RLock()
defer tp.mtx.RUnlock()
return tp.tip
} | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"Tip",
"(",
")",
"int64",
"{",
"tp",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"tp",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"tp",
".",
"tip",
"\n",
"}"
] | // Tip returns the current length of the diffs slice. | [
"Tip",
"returns",
"the",
"current",
"length",
"of",
"the",
"diffs",
"slice",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L335-L339 |
20,284 | decred/dcrdata | stakedb/ticketpool.go | Cursor | func (tp *TicketPool) Cursor() int64 {
tp.mtx.RLock()
defer tp.mtx.RUnlock()
return tp.cursor
} | go | func (tp *TicketPool) Cursor() int64 {
tp.mtx.RLock()
defer tp.mtx.RUnlock()
return tp.cursor
} | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"Cursor",
"(",
")",
"int64",
"{",
"tp",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"tp",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"tp",
".",
"cursor",
"\n",
"}"
] | // Cursor returns the current cursor, the location of the next unapplied diff. | [
"Cursor",
"returns",
"the",
"current",
"cursor",
"the",
"location",
"of",
"the",
"next",
"unapplied",
"diff",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L342-L346 |
20,285 | decred/dcrdata | stakedb/ticketpool.go | append | func (tp *TicketPool) append(diff *PoolDiff) {
tp.tip++
tp.diffs = append(tp.diffs, *diff)
} | go | func (tp *TicketPool) append(diff *PoolDiff) {
tp.tip++
tp.diffs = append(tp.diffs, *diff)
} | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"append",
"(",
"diff",
"*",
"PoolDiff",
")",
"{",
"tp",
".",
"tip",
"++",
"\n",
"tp",
".",
"diffs",
"=",
"append",
"(",
"tp",
".",
"diffs",
",",
"*",
"diff",
")",
"\n",
"}"
] | // append grows the diffs slice and advances the tip height. | [
"append",
"grows",
"the",
"diffs",
"slice",
"and",
"advances",
"the",
"tip",
"height",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L349-L352 |
20,286 | decred/dcrdata | stakedb/ticketpool.go | trim | func (tp *TicketPool) trim() (int64, PoolDiff) {
if tp.tip == 0 || len(tp.diffs) == 0 {
return tp.tip, PoolDiff{}
}
tp.tip--
newMaxCursor := tp.maxCursor()
if tp.cursor > newMaxCursor {
if err := tp.retreatTo(newMaxCursor); err != nil {
log.Errorf("retreatTo failed: %v", err)
}
}
// Trim AFTER retreatin... | go | func (tp *TicketPool) trim() (int64, PoolDiff) {
if tp.tip == 0 || len(tp.diffs) == 0 {
return tp.tip, PoolDiff{}
}
tp.tip--
newMaxCursor := tp.maxCursor()
if tp.cursor > newMaxCursor {
if err := tp.retreatTo(newMaxCursor); err != nil {
log.Errorf("retreatTo failed: %v", err)
}
}
// Trim AFTER retreatin... | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"trim",
"(",
")",
"(",
"int64",
",",
"PoolDiff",
")",
"{",
"if",
"tp",
".",
"tip",
"==",
"0",
"||",
"len",
"(",
"tp",
".",
"diffs",
")",
"==",
"0",
"{",
"return",
"tp",
".",
"tip",
",",
"PoolDiff",
"... | // trim is the non-thread-safe version of Trim. | [
"trim",
"is",
"the",
"non",
"-",
"thread",
"-",
"safe",
"version",
"of",
"Trim",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L355-L370 |
20,287 | decred/dcrdata | stakedb/ticketpool.go | Trim | func (tp *TicketPool) Trim() (int64, PoolDiff) {
tp.mtx.Lock()
defer tp.mtx.Unlock()
return tp.trim()
} | go | func (tp *TicketPool) Trim() (int64, PoolDiff) {
tp.mtx.Lock()
defer tp.mtx.Unlock()
return tp.trim()
} | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"Trim",
"(",
")",
"(",
"int64",
",",
"PoolDiff",
")",
"{",
"tp",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"tp",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"return",
"tp",
".",
"trim",
"(",
"... | // Trim removes the end diff and decrements the tip height. If the cursor would
// fall beyond the end of the diffs, the removed diffs are applied in reverse. | [
"Trim",
"removes",
"the",
"end",
"diff",
"and",
"decrements",
"the",
"tip",
"height",
".",
"If",
"the",
"cursor",
"would",
"fall",
"beyond",
"the",
"end",
"of",
"the",
"diffs",
"the",
"removed",
"diffs",
"are",
"applied",
"in",
"reverse",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L374-L378 |
20,288 | decred/dcrdata | stakedb/ticketpool.go | storeDiff | func storeDiff(db *badger.DB, diff *PoolDiff, height int64) error {
var heightBytes [8]byte
binary.BigEndian.PutUint64(heightBytes[:], uint64(height))
var poolDiffBuffer bytes.Buffer
if err := gob.NewEncoder(&poolDiffBuffer).Encode(diff); err != nil {
return err
}
return db.Update(func(txn *badger.Txn) error ... | go | func storeDiff(db *badger.DB, diff *PoolDiff, height int64) error {
var heightBytes [8]byte
binary.BigEndian.PutUint64(heightBytes[:], uint64(height))
var poolDiffBuffer bytes.Buffer
if err := gob.NewEncoder(&poolDiffBuffer).Encode(diff); err != nil {
return err
}
return db.Update(func(txn *badger.Txn) error ... | [
"func",
"storeDiff",
"(",
"db",
"*",
"badger",
".",
"DB",
",",
"diff",
"*",
"PoolDiff",
",",
"height",
"int64",
")",
"error",
"{",
"var",
"heightBytes",
"[",
"8",
"]",
"byte",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"heightBytes",
"[",... | // storeDiff stores the input diff for the specified height in the on-disk DB. | [
"storeDiff",
"stores",
"the",
"input",
"diff",
"for",
"the",
"specified",
"height",
"in",
"the",
"on",
"-",
"disk",
"DB",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L381-L393 |
20,289 | decred/dcrdata | stakedb/ticketpool.go | storeDiffs | func storeDiffs(db *badger.DB, diffs []*PoolDiff, heights []int64) error {
heightToBytes := func(height int64) (heightBytes [8]byte) {
binary.BigEndian.PutUint64(heightBytes[:], uint64(height))
return
}
poolDiffBuffer := new(bytes.Buffer)
txn := db.NewTransaction(true)
for i, h := range heights {
heightByte... | go | func storeDiffs(db *badger.DB, diffs []*PoolDiff, heights []int64) error {
heightToBytes := func(height int64) (heightBytes [8]byte) {
binary.BigEndian.PutUint64(heightBytes[:], uint64(height))
return
}
poolDiffBuffer := new(bytes.Buffer)
txn := db.NewTransaction(true)
for i, h := range heights {
heightByte... | [
"func",
"storeDiffs",
"(",
"db",
"*",
"badger",
".",
"DB",
",",
"diffs",
"[",
"]",
"*",
"PoolDiff",
",",
"heights",
"[",
"]",
"int64",
")",
"error",
"{",
"heightToBytes",
":=",
"func",
"(",
"height",
"int64",
")",
"(",
"heightBytes",
"[",
"8",
"]",
... | // storeDiffs stores the input diffs for the specified heights in the on-disk DB. | [
"storeDiffs",
"stores",
"the",
"input",
"diffs",
"for",
"the",
"specified",
"heights",
"in",
"the",
"on",
"-",
"disk",
"DB",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L396-L432 |
20,290 | decred/dcrdata | stakedb/ticketpool.go | fetchDiff | func (tp *TicketPool) fetchDiff(height int64) (*PoolDiffDBItem, error) {
var heightBytes [8]byte
binary.BigEndian.PutUint64(heightBytes[:], uint64(height))
var diff *PoolDiffDBItem
err := tp.diffDB.View(func(txn *badger.Txn) error {
item, errTx := txn.Get(heightBytes[:])
if errTx != nil {
return fmt.Errorf(... | go | func (tp *TicketPool) fetchDiff(height int64) (*PoolDiffDBItem, error) {
var heightBytes [8]byte
binary.BigEndian.PutUint64(heightBytes[:], uint64(height))
var diff *PoolDiffDBItem
err := tp.diffDB.View(func(txn *badger.Txn) error {
item, errTx := txn.Get(heightBytes[:])
if errTx != nil {
return fmt.Errorf(... | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"fetchDiff",
"(",
"height",
"int64",
")",
"(",
"*",
"PoolDiffDBItem",
",",
"error",
")",
"{",
"var",
"heightBytes",
"[",
"8",
"]",
"byte",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"heightBytes",
... | // fetchDiff retrieves the diff at the specified height from the on-disk DB. | [
"fetchDiff",
"retrieves",
"the",
"diff",
"at",
"the",
"specified",
"height",
"from",
"the",
"on",
"-",
"disk",
"DB",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L439-L477 |
20,291 | decred/dcrdata | stakedb/ticketpool.go | Append | func (tp *TicketPool) Append(diff *PoolDiff, height int64) error {
if height != tp.tip+1 {
return fmt.Errorf("block height %d does not build on %d", height, tp.tip)
}
tp.mtx.Lock()
defer tp.mtx.Unlock()
tp.append(diff)
return tp.storeDiff(diff, height)
} | go | func (tp *TicketPool) Append(diff *PoolDiff, height int64) error {
if height != tp.tip+1 {
return fmt.Errorf("block height %d does not build on %d", height, tp.tip)
}
tp.mtx.Lock()
defer tp.mtx.Unlock()
tp.append(diff)
return tp.storeDiff(diff, height)
} | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"Append",
"(",
"diff",
"*",
"PoolDiff",
",",
"height",
"int64",
")",
"error",
"{",
"if",
"height",
"!=",
"tp",
".",
"tip",
"+",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"height",
"... | // Append grows the diffs slice with the specified diff, and stores it in the
// on-disk DB. The height of the diff is used to check that it builds on the
// chain tip, and as a primary key in the DB. | [
"Append",
"grows",
"the",
"diffs",
"slice",
"with",
"the",
"specified",
"diff",
"and",
"stores",
"it",
"in",
"the",
"on",
"-",
"disk",
"DB",
".",
"The",
"height",
"of",
"the",
"diff",
"is",
"used",
"to",
"check",
"that",
"it",
"builds",
"on",
"the",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L482-L490 |
20,292 | decred/dcrdata | stakedb/ticketpool.go | AppendAndAdvancePool | func (tp *TicketPool) AppendAndAdvancePool(diff *PoolDiff, height int64) error {
if height != tp.tip+1 {
return fmt.Errorf("block height %d does not build on %d", height, tp.tip)
}
tp.mtx.Lock()
defer tp.mtx.Unlock()
tp.append(diff)
if err := tp.storeDiff(diff, height); err != nil {
return err
}
return tp.a... | go | func (tp *TicketPool) AppendAndAdvancePool(diff *PoolDiff, height int64) error {
if height != tp.tip+1 {
return fmt.Errorf("block height %d does not build on %d", height, tp.tip)
}
tp.mtx.Lock()
defer tp.mtx.Unlock()
tp.append(diff)
if err := tp.storeDiff(diff, height); err != nil {
return err
}
return tp.a... | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"AppendAndAdvancePool",
"(",
"diff",
"*",
"PoolDiff",
",",
"height",
"int64",
")",
"error",
"{",
"if",
"height",
"!=",
"tp",
".",
"tip",
"+",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
... | // AppendAndAdvancePool functions like Append, except that after growing the
// diffs slice and storing the diff in DB, the ticket pool is advanced. | [
"AppendAndAdvancePool",
"functions",
"like",
"Append",
"except",
"that",
"after",
"growing",
"the",
"diffs",
"slice",
"and",
"storing",
"the",
"diff",
"in",
"DB",
"the",
"ticket",
"pool",
"is",
"advanced",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L494-L505 |
20,293 | decred/dcrdata | stakedb/ticketpool.go | currentPool | func (tp *TicketPool) currentPool() ([]chainhash.Hash, int64) {
poolSize := len(tp.pool)
// allocate space for all the ticket hashes, but use append to avoid the
// slice initialization having to zero initialize all of the arrays.
pool := make([]chainhash.Hash, 0, poolSize)
for h := range tp.pool {
pool = append... | go | func (tp *TicketPool) currentPool() ([]chainhash.Hash, int64) {
poolSize := len(tp.pool)
// allocate space for all the ticket hashes, but use append to avoid the
// slice initialization having to zero initialize all of the arrays.
pool := make([]chainhash.Hash, 0, poolSize)
for h := range tp.pool {
pool = append... | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"currentPool",
"(",
")",
"(",
"[",
"]",
"chainhash",
".",
"Hash",
",",
"int64",
")",
"{",
"poolSize",
":=",
"len",
"(",
"tp",
".",
"pool",
")",
"\n",
"// allocate space for all the ticket hashes, but use append to avo... | // currentPool is the non-thread-safe version of CurrentPool. | [
"currentPool",
"is",
"the",
"non",
"-",
"thread",
"-",
"safe",
"version",
"of",
"CurrentPool",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L508-L517 |
20,294 | decred/dcrdata | stakedb/ticketpool.go | CurrentPoolSize | func (tp *TicketPool) CurrentPoolSize() int {
tp.mtx.RLock()
defer tp.mtx.RUnlock()
return len(tp.pool)
} | go | func (tp *TicketPool) CurrentPoolSize() int {
tp.mtx.RLock()
defer tp.mtx.RUnlock()
return len(tp.pool)
} | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"CurrentPoolSize",
"(",
")",
"int",
"{",
"tp",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"tp",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"len",
"(",
"tp",
".",
"pool",
")",
"\n",
"... | // CurrentPoolSize returns the number of tickets stored in the current pool map. | [
"CurrentPoolSize",
"returns",
"the",
"number",
"of",
"tickets",
"stored",
"in",
"the",
"current",
"pool",
"map",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L530-L534 |
20,295 | decred/dcrdata | stakedb/ticketpool.go | advance | func (tp *TicketPool) advance() error {
if tp.cursor > tp.maxCursor() {
return fmt.Errorf("cursor at tip, unable to advance")
}
diffToNext := tp.diffs[tp.cursor]
initPoolSize := len(tp.pool)
expectedFinalSize := initPoolSize + len(diffToNext.In) - len(diffToNext.Out)
tp.applyDiff(diffToNext.In, diffToNext.Out... | go | func (tp *TicketPool) advance() error {
if tp.cursor > tp.maxCursor() {
return fmt.Errorf("cursor at tip, unable to advance")
}
diffToNext := tp.diffs[tp.cursor]
initPoolSize := len(tp.pool)
expectedFinalSize := initPoolSize + len(diffToNext.In) - len(diffToNext.Out)
tp.applyDiff(diffToNext.In, diffToNext.Out... | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"advance",
"(",
")",
"error",
"{",
"if",
"tp",
".",
"cursor",
">",
"tp",
".",
"maxCursor",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"diffToNext",
":=",
"tp"... | // advance applies the pool diff at the current cursor location, and advances
// the cursor. Note that when advancing at the last diff, the resulting cursor
// will be beyond the last element in the diffs slice. | [
"advance",
"applies",
"the",
"pool",
"diff",
"at",
"the",
"current",
"cursor",
"location",
"and",
"advances",
"the",
"cursor",
".",
"Note",
"that",
"when",
"advancing",
"at",
"the",
"last",
"diff",
"the",
"resulting",
"cursor",
"will",
"be",
"beyond",
"the",... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L564-L582 |
20,296 | decred/dcrdata | stakedb/ticketpool.go | advanceTo | func (tp *TicketPool) advanceTo(height int64) error {
if height > tp.tip {
return fmt.Errorf("cannot advance past tip")
}
for height > tp.cursor {
if err := tp.advance(); err != nil {
return err
}
}
return nil
} | go | func (tp *TicketPool) advanceTo(height int64) error {
if height > tp.tip {
return fmt.Errorf("cannot advance past tip")
}
for height > tp.cursor {
if err := tp.advance(); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"advanceTo",
"(",
"height",
"int64",
")",
"error",
"{",
"if",
"height",
">",
"tp",
".",
"tip",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"height",
">",
"tp",
".",... | // advanceTo successively applies pool diffs with advance until the cursor
// reaches the desired height. Note that this function will return without error
// if the initial cursor is at or beyond the specified height. | [
"advanceTo",
"successively",
"applies",
"pool",
"diffs",
"with",
"advance",
"until",
"the",
"cursor",
"reaches",
"the",
"desired",
"height",
".",
"Note",
"that",
"this",
"function",
"will",
"return",
"without",
"error",
"if",
"the",
"initial",
"cursor",
"is",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L587-L597 |
20,297 | decred/dcrdata | stakedb/ticketpool.go | AdvanceToTip | func (tp *TicketPool) AdvanceToTip() (int64, error) {
tp.mtx.Lock()
defer tp.mtx.Unlock()
err := tp.advanceTo(tp.tip)
return tp.cursor - 1, err
} | go | func (tp *TicketPool) AdvanceToTip() (int64, error) {
tp.mtx.Lock()
defer tp.mtx.Unlock()
err := tp.advanceTo(tp.tip)
return tp.cursor - 1, err
} | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"AdvanceToTip",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"tp",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"tp",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"err",
":=",
"tp",
".",
"advance... | // AdvanceToTip advances the pool map by applying all stored diffs. Note that
// the cursor will stop just beyond the last element of the diffs slice. It will
// not be possible to advance further, only retreat. | [
"AdvanceToTip",
"advances",
"the",
"pool",
"map",
"by",
"applying",
"all",
"stored",
"diffs",
".",
"Note",
"that",
"the",
"cursor",
"will",
"stop",
"just",
"beyond",
"the",
"last",
"element",
"of",
"the",
"diffs",
"slice",
".",
"It",
"will",
"not",
"be",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L602-L607 |
20,298 | decred/dcrdata | stakedb/ticketpool.go | retreat | func (tp *TicketPool) retreat() error {
if tp.cursor == 0 {
return fmt.Errorf("cursor at genesis, unable to retreat")
}
diffFromPrev := tp.diffs[tp.cursor-1]
initPoolSize := len(tp.pool)
expectedFinalSize := initPoolSize - len(diffFromPrev.In) + len(diffFromPrev.Out)
tp.applyDiff(diffFromPrev.Out, diffFromPre... | go | func (tp *TicketPool) retreat() error {
if tp.cursor == 0 {
return fmt.Errorf("cursor at genesis, unable to retreat")
}
diffFromPrev := tp.diffs[tp.cursor-1]
initPoolSize := len(tp.pool)
expectedFinalSize := initPoolSize - len(diffFromPrev.In) + len(diffFromPrev.Out)
tp.applyDiff(diffFromPrev.Out, diffFromPre... | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"retreat",
"(",
")",
"error",
"{",
"if",
"tp",
".",
"cursor",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"diffFromPrev",
":=",
"tp",
".",
"diffs",
"[",
"tp",... | // retreat applies the previous diff in reverse, moving the pool map to the
// state before that diff was applied. The cursor is decremented, and may go to
// 0 but not beyond as the cursor is the location of the next unapplied diff. | [
"retreat",
"applies",
"the",
"previous",
"diff",
"in",
"reverse",
"moving",
"the",
"pool",
"map",
"to",
"the",
"state",
"before",
"that",
"diff",
"was",
"applied",
".",
"The",
"cursor",
"is",
"decremented",
"and",
"may",
"go",
"to",
"0",
"but",
"not",
"b... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L612-L628 |
20,299 | decred/dcrdata | stakedb/ticketpool.go | retreatTo | func (tp *TicketPool) retreatTo(height int64) error {
if height < 0 || height > tp.tip {
return fmt.Errorf("Invalid destination cursor %d", height)
}
for tp.cursor > height {
if err := tp.retreat(); err != nil {
return err
}
}
return nil
} | go | func (tp *TicketPool) retreatTo(height int64) error {
if height < 0 || height > tp.tip {
return fmt.Errorf("Invalid destination cursor %d", height)
}
for tp.cursor > height {
if err := tp.retreat(); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"tp",
"*",
"TicketPool",
")",
"retreatTo",
"(",
"height",
"int64",
")",
"error",
"{",
"if",
"height",
"<",
"0",
"||",
"height",
">",
"tp",
".",
"tip",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"height",
")",
"\n",
"}... | // retreatTo successively applies pool diffs in reverse with retreate until the
// cursor reaches the desired height. Note that this function will return
// without error if the initial cursor is at or below the specified height. | [
"retreatTo",
"successively",
"applies",
"pool",
"diffs",
"in",
"reverse",
"with",
"retreate",
"until",
"the",
"cursor",
"reaches",
"the",
"desired",
"height",
".",
"Note",
"that",
"this",
"function",
"will",
"return",
"without",
"error",
"if",
"the",
"initial",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/ticketpool.go#L642-L652 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.