本文整理汇总了Golang中github.com/decred/dcrd/blockchain/stake.TicketDB.DumpMissedTickets方法的典型用法代码示例。如果您正苦于以下问题:Golang TicketDB.DumpMissedTickets方法的具体用法?Golang TicketDB.DumpMissedTickets怎么用?Golang TicketDB.DumpMissedTickets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/decred/dcrd/blockchain/stake.TicketDB
的用法示例。
在下文中一共展示了TicketDB.DumpMissedTickets方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DebugTicketDBMissedString
// DebugTicketDBMissedString prints out the contents of the missed ticket
// database to a string. If verbose is indicated, the ticket data itself
// is printed along with the ticket hashes.
func DebugTicketDBMissedString(tmdb *stake.TicketDB, verbose bool) (string, error) {
var buffer bytes.Buffer
str := fmt.Sprintf("Contents of missed ticket database:\n")
buffer.WriteString(str)
bucketTickets, err := tmdb.DumpMissedTickets()
if err != nil {
return "", err
}
for hash, td := range bucketTickets {
str = fmt.Sprintf("%v\n", hash)
buffer.WriteString(str)
if verbose {
str = fmt.Sprintf("%v\n", DebugTicketDataString(td))
buffer.WriteString(str)
}
}
return buffer.String(), nil
}
示例2: TicketDbThumbprint
// TicketDbThumbprint takes all the tickets in the respective ticket db,
// sorts them, hashes their contents into a list, and then hashes that list.
// The resultant hash is the thumbprint of the ticket database, and should
// be the same across all clients that are synced to the same block. Returns
// an array of hashes len 3, containing (1) live tickets (2) spent tickets
// and (3) missed tickets.
// Do NOT use on mainnet or in production. For debug use only! Make sure
// the blockchain is frozen when you call this function.
func TicketDbThumbprint(tmdb *stake.TicketDB, chainParams *chaincfg.Params) ([]*chainhash.Hash, error) {
// Container for the three master hashes to go into.
dbThumbprints := make([]*chainhash.Hash, 3, 3)
// (1) Live tickets.
allLiveTickets := stake.NewTicketDataSliceEmpty()
for i := 0; i < stake.BucketsSize; i++ {
bucketTickets, err := tmdb.DumpLiveTickets(uint8(i))
if err != nil {
return nil, err
}
for _, td := range bucketTickets {
allLiveTickets = append(allLiveTickets, td)
}
}
// Sort by the number data hash, since we already have this implemented
// and it's also unique.
sort.Sort(allLiveTickets)
// Create a buffer, dump all the data into it, and hash.
var buf bytes.Buffer
for _, td := range allLiveTickets {
writeTicketDataToBuf(&buf, td)
}
liveHash := chainhash.HashFunc(buf.Bytes())
liveThumbprint, err := chainhash.NewHash(liveHash[:])
if err != nil {
return nil, err
}
dbThumbprints[0] = liveThumbprint
// (2) Spent tickets.
height := tmdb.GetTopBlock()
allSpentTickets := stake.NewTicketDataSliceEmpty()
for i := int64(chainParams.StakeEnabledHeight); i <= height; i++ {
bucketTickets, err := tmdb.DumpSpentTickets(i)
if err != nil {
return nil, err
}
for _, td := range bucketTickets {
allSpentTickets = append(allSpentTickets, td)
}
}
sort.Sort(allSpentTickets)
buf.Reset() // Flush buffer
for _, td := range allSpentTickets {
writeTicketDataToBuf(&buf, td)
}
spentHash := chainhash.HashFunc(buf.Bytes())
spentThumbprint, err := chainhash.NewHash(spentHash[:])
if err != nil {
return nil, err
}
dbThumbprints[1] = spentThumbprint
// (3) Missed tickets.
allMissedTickets := stake.NewTicketDataSliceEmpty()
missedTickets, err := tmdb.DumpMissedTickets()
if err != nil {
return nil, err
}
for _, td := range missedTickets {
allMissedTickets = append(allMissedTickets, td)
}
sort.Sort(allMissedTickets)
buf.Reset() // Flush buffer
missedHash := chainhash.HashFunc(buf.Bytes())
missedThumbprint, err := chainhash.NewHash(missedHash[:])
if err != nil {
return nil, err
}
dbThumbprints[2] = missedThumbprint
return dbThumbprints, nil
}
示例3: TestTicketDB
//.........这里部分代码省略.........
// Create snapshot of tmdb at block 168
CopyOfMapsAtBlock168, err = cloneTicketDB(&tmdb)
if err != nil {
t.Errorf("db cloning at block 168 failure! %v", err)
}
}
}
// Remove five blocks from HEAD~1
_, _, _, err = tmdb.RemoveBlockToHeight(50)
if err != nil {
t.Errorf("error: %v", err)
}
// Test if the roll back was symmetric to the earlier snapshot
if !reflect.DeepEqual(tmdb.DumpMapsPointer(), CopyOfMapsAtBlock50) {
t.Errorf("The td did not restore to a previous block height correctly!")
}
// Test rescanning a ticket db
err = tmdb.RescanTicketDB()
if err != nil {
t.Errorf("rescanticketdb err: %v", err.Error())
}
// Test if the db file storage was symmetric to the earlier snapshot
if !reflect.DeepEqual(tmdb.DumpMapsPointer(), CopyOfMapsAtBlock168) {
t.Errorf("The td did not rescan to HEAD correctly!")
}
err = os.Mkdir("testdata/", os.FileMode(0700))
if err != nil {
t.Error(err)
}
// Store the ticket db to disk
err = tmdb.Store("testdata/", "testtmdb")
if err != nil {
t.Errorf("error: %v", err)
}
var tmdb2 stake.TicketDB
err = tmdb2.LoadTicketDBs("testdata/", "testtmdb", simNetParams, database)
if err != nil {
t.Errorf("error: %v", err)
}
// Test if the db file storage was symmetric to previously rescanned one
if !reflect.DeepEqual(tmdb.DumpMapsPointer(), tmdb2.DumpMapsPointer()) {
t.Errorf("The td did not rescan to a previous block height correctly!")
}
tmdb2.Close()
// Test dumping missing tickets from block 152
missedIn152, _ := chainhash.NewHashFromStr(
"84f7f866b0af1cc278cb8e0b2b76024a07542512c76487c83628c14c650de4fa")
tmdb.RemoveBlockToHeight(152)
missedTix, err := tmdb.DumpMissedTickets()
if err != nil {
t.Errorf("err dumping missed tix: %v", err.Error())
}
if _, exists := missedTix[*missedIn152]; !exists {
t.Errorf("couldn't finding missed tx 1 %v in tmdb @ block 152!",
missedIn152)
}
tmdb.RescanTicketDB()
// Make sure that the revoked map contains the revoked tx
revokedSlice := []*chainhash.Hash{missedIn152}
revokedTix, err := tmdb.DumpRevokedTickets()
if err != nil {
t.Errorf("err dumping missed tix: %v", err.Error())
}
if len(revokedTix) != 1 {
t.Errorf("revoked ticket map is wrong len, got %v, want %v",
len(revokedTix), 1)
}
_, wasMissedIn152 := revokedTix[*revokedSlice[0]]
ticketsRevoked := wasMissedIn152
if !ticketsRevoked {
t.Errorf("revoked ticket map did not include tickets missed in " +
"block 152 and later revoked")
}
database.Close()
tmdb.Close()
os.RemoveAll("ticketdb_test")
os.Remove("./ticketdb_test.ver")
os.Remove("testdata/testtmdb")
os.Remove("testdata")
}