mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 14:35:53 +00:00
Some changes
This commit is contained in:
parent
c0f4301099
commit
bc77fe1b4d
@ -312,6 +312,10 @@ var RPCMessageCommandToString = map[MessageCommand]string{
|
|||||||
CmdGetFeeEstimateResponseMessage: "GetFeeEstimateResponse",
|
CmdGetFeeEstimateResponseMessage: "GetFeeEstimateResponse",
|
||||||
CmdSubmitTransactionReplacementRequestMessage: "SubmitTransactionReplacementRequest",
|
CmdSubmitTransactionReplacementRequestMessage: "SubmitTransactionReplacementRequest",
|
||||||
CmdSubmitTransactionReplacementResponseMessage: "SubmitTransactionReplacementResponse",
|
CmdSubmitTransactionReplacementResponseMessage: "SubmitTransactionReplacementResponse",
|
||||||
|
CmdGetPruningWindowRootsRequestMessage: "GetPruningWindowRootsRequestMessage",
|
||||||
|
CmdGetPruningWindowRootsResponseMessage: "GetPruningWindowRootsResponseMessage",
|
||||||
|
CmdAddArchivalBlocksRequestMessage: "AddArchivalBlocksRequestMessage",
|
||||||
|
CmdAddArchivalBlocksResponseMessage: "AddArchivalBlocksResponseMessage",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message is an interface that describes a kaspa message. A type that
|
// Message is an interface that describes a kaspa message. A type that
|
||||||
|
|||||||
@ -9,17 +9,17 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/domain/consensus"
|
"github.com/kaspanet/kaspad/domain/consensus"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model"
|
"github.com/kaspanet/kaspad/domain/consensus/model"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/config"
|
"github.com/kaspanet/kaspad/infrastructure/config"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/db/database"
|
"github.com/kaspanet/kaspad/infrastructure/db/database"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/rpcclient"
|
"github.com/kaspanet/kaspad/infrastructure/network/rpcclient"
|
||||||
"github.com/kaspanet/kaspad/util/panics"
|
|
||||||
"github.com/kaspanet/kaspad/util/profiling"
|
"github.com/kaspanet/kaspad/util/profiling"
|
||||||
"github.com/kaspanet/kaspad/version"
|
"github.com/kaspanet/kaspad/version"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
defer panics.HandlePanic(log, "MAIN", nil)
|
// defer panics.HandlePanic(log, "MAIN", nil)
|
||||||
|
|
||||||
cfg, err := parseConfig()
|
cfg, err := parseConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -43,10 +43,11 @@ func main() {
|
|||||||
|
|
||||||
func mainImpl(cfg *configFlags) error {
|
func mainImpl(cfg *configFlags) error {
|
||||||
dataDir := filepath.Join(config.DefaultAppDir)
|
dataDir := filepath.Join(config.DefaultAppDir)
|
||||||
dbPath := filepath.Join(dataDir, "db")
|
dbPath := filepath.Join(dataDir, "kaspa-mainnet/datadir2")
|
||||||
consensusConfig := &consensus.Config{Params: *cfg.NetParams()}
|
consensusConfig := &consensus.Config{Params: *cfg.NetParams()}
|
||||||
factory := consensus.NewFactory()
|
factory := consensus.NewFactory()
|
||||||
factory.SetTestDataDir(dbPath)
|
factory.SetTestDataDir(dbPath)
|
||||||
|
factory.AutoSetActivePrefix(true)
|
||||||
tc, tearDownFunc, err := factory.NewTestConsensus(consensusConfig, "archiveexport")
|
tc, tearDownFunc, err := factory.NewTestConsensus(consensusConfig, "archiveexport")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -72,16 +73,17 @@ func mainImpl(cfg *configFlags) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, root := range rootsResp.Roots {
|
||||||
|
log.Infof("Got root %s", root.Root)
|
||||||
|
}
|
||||||
|
|
||||||
for _, root := range rootsResp.Roots {
|
for _, root := range rootsResp.Roots {
|
||||||
rootHash, err := externalapi.NewDomainHashFromString(root.Root)
|
rootHash, err := externalapi.NewDomainHashFromString(root.Root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rootHeader, err := tc.BlockHeaderStore().BlockHeader(tc.DatabaseContext(), model.NewStagingArea(), rootHash)
|
log.Infof("Adding past of %s", rootHash)
|
||||||
if database.IsNotFoundError(err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -93,10 +95,7 @@ func mainImpl(cfg *configFlags) error {
|
|||||||
|
|
||||||
// TODO: Since GD data is not always available, we should extract the blue work from the header and use that for topological traversal
|
// TODO: Since GD data is not always available, we should extract the blue work from the header and use that for topological traversal
|
||||||
heap := tc.DAGTraversalManager().NewDownHeap(model.NewStagingArea())
|
heap := tc.DAGTraversalManager().NewDownHeap(model.NewStagingArea())
|
||||||
for _, parent := range rootHeader.DirectParents() {
|
heap.Push(rootHash)
|
||||||
heap.Push(parent)
|
|
||||||
blockToChild[*parent] = *rootHash
|
|
||||||
}
|
|
||||||
|
|
||||||
visited := make(map[externalapi.DomainHash]struct{})
|
visited := make(map[externalapi.DomainHash]struct{})
|
||||||
chunk := make([]*appmessage.ArchivalBlock, 0, 1000)
|
chunk := make([]*appmessage.ArchivalBlock, 0, 1000)
|
||||||
@ -127,13 +126,21 @@ func mainImpl(cfg *configFlags) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
chunk = append(chunk, &appmessage.ArchivalBlock{
|
archivalBlock := &appmessage.ArchivalBlock{
|
||||||
Block: appmessage.DomainBlockToRPCBlock(block),
|
Block: appmessage.DomainBlockToRPCBlock(block),
|
||||||
Child: blockToChild[*hash].String(),
|
}
|
||||||
})
|
if child, ok := blockToChild[*hash]; ok {
|
||||||
|
archivalBlock.Child = child.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
chunk = append(chunk, archivalBlock)
|
||||||
|
|
||||||
|
if len(chunk) == 1 {
|
||||||
|
log.Infof("Added %s to chunk", consensushashing.BlockHash(block))
|
||||||
|
}
|
||||||
|
|
||||||
if len(chunk) == cap(chunk) {
|
if len(chunk) == cap(chunk) {
|
||||||
_, err := rpcClient.AddArchivalBlocks(chunk)
|
err := sendChunk(rpcClient, chunk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -146,6 +153,39 @@ func mainImpl(cfg *configFlags) error {
|
|||||||
blockToChild[*parent] = *hash
|
blockToChild[*parent] = *hash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(chunk) > 0 {
|
||||||
|
sendChunk(rpcClient, chunk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendChunk(rpcClient *rpcclient.RPCClient, chunk []*appmessage.ArchivalBlock) error {
|
||||||
|
log.Infof("Sending chunk")
|
||||||
|
_, err := rpcClient.AddArchivalBlocks(chunk)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Infof("Sent chunk")
|
||||||
|
|
||||||
|
// Checking existence of first block for sanity
|
||||||
|
block := chunk[0]
|
||||||
|
domainBlock, err := appmessage.RPCBlockToDomainBlock(block.Block)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
blockHash := consensushashing.BlockHash(domainBlock)
|
||||||
|
log.Infof("Checking block %s", blockHash)
|
||||||
|
resp, err := rpcClient.GetBlock(blockHash.String(), true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(resp.Block.Transactions) == 0 {
|
||||||
|
return errors.Errorf("Block %s has no transactions on the server", blockHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/domain/consensus/processes/blockparentbuilder"
|
"github.com/kaspanet/kaspad/domain/consensus/processes/blockparentbuilder"
|
||||||
parentssanager "github.com/kaspanet/kaspad/domain/consensus/processes/parentsmanager"
|
parentssanager "github.com/kaspanet/kaspad/domain/consensus/processes/parentsmanager"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/processes/pruningproofmanager"
|
"github.com/kaspanet/kaspad/domain/consensus/processes/pruningproofmanager"
|
||||||
|
"github.com/kaspanet/kaspad/domain/prefixmanager"
|
||||||
"github.com/kaspanet/kaspad/util/staging"
|
"github.com/kaspanet/kaspad/util/staging"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
@ -89,6 +90,8 @@ type Factory interface {
|
|||||||
SetTestPreAllocateCache(preallocateCaches bool)
|
SetTestPreAllocateCache(preallocateCaches bool)
|
||||||
SetTestPastMedianTimeManager(medianTimeConstructor PastMedianTimeManagerConstructor)
|
SetTestPastMedianTimeManager(medianTimeConstructor PastMedianTimeManagerConstructor)
|
||||||
SetTestDifficultyManager(difficultyConstructor DifficultyManagerConstructor)
|
SetTestDifficultyManager(difficultyConstructor DifficultyManagerConstructor)
|
||||||
|
|
||||||
|
AutoSetActivePrefix(value bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
type factory struct {
|
type factory struct {
|
||||||
@ -98,6 +101,7 @@ type factory struct {
|
|||||||
difficultyConstructor DifficultyManagerConstructor
|
difficultyConstructor DifficultyManagerConstructor
|
||||||
cacheSizeMiB *int
|
cacheSizeMiB *int
|
||||||
preallocateCaches *bool
|
preallocateCaches *bool
|
||||||
|
autoCheckActivePrefix bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFactory creates a new Consensus factory
|
// NewFactory creates a new Consensus factory
|
||||||
@ -106,6 +110,7 @@ func NewFactory() Factory {
|
|||||||
ghostdagConstructor: ghostdagmanager.New,
|
ghostdagConstructor: ghostdagmanager.New,
|
||||||
pastMedianTimeConsructor: pastmediantimemanager.New,
|
pastMedianTimeConsructor: pastmediantimemanager.New,
|
||||||
difficultyConstructor: difficultymanager.New,
|
difficultyConstructor: difficultymanager.New,
|
||||||
|
autoCheckActivePrefix: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -588,8 +593,19 @@ func (f *factory) NewTestConsensus(config *Config, testName string) (
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
testConsensusDBPrefix := &prefix.Prefix{}
|
prefix := &prefix.Prefix{}
|
||||||
consensusAsInterface, shouldMigrate, err := f.NewConsensus(config, db, testConsensusDBPrefix, nil)
|
if f.autoCheckActivePrefix {
|
||||||
|
activePrefix, exists, err := prefixmanager.ActivePrefix(db)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if exists {
|
||||||
|
prefix = activePrefix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
consensusAsInterface, shouldMigrate, err := f.NewConsensus(config, db, prefix, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -648,6 +664,11 @@ func (f *factory) SetTestPreAllocateCache(preallocateCaches bool) {
|
|||||||
f.preallocateCaches = &preallocateCaches
|
f.preallocateCaches = &preallocateCaches
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AutoSetActivePrefix implements Factory.
|
||||||
|
func (f *factory) AutoSetActivePrefix(value bool) {
|
||||||
|
f.autoCheckActivePrefix = value
|
||||||
|
}
|
||||||
|
|
||||||
func dagStores(config *Config,
|
func dagStores(config *Config,
|
||||||
prefixBucket model.DBBucket,
|
prefixBucket model.DBBucket,
|
||||||
pruningWindowSizePlusFinalityDepthForCache, pruningWindowSizeForCaches int,
|
pruningWindowSizePlusFinalityDepthForCache, pruningWindowSizeForCaches int,
|
||||||
|
|||||||
@ -46,7 +46,7 @@ func (x *KaspadMessage_AddArchivalBlocksRequest) fromAppMessage(message *appmess
|
|||||||
}
|
}
|
||||||
|
|
||||||
x.AddArchivalBlocksRequest = &AddArchivalBlocksRequestMessage{
|
x.AddArchivalBlocksRequest = &AddArchivalBlocksRequestMessage{
|
||||||
Blocks: make([]*ArchivalBlock, len(message.Blocks)),
|
Blocks: blocks,
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ func (x *AddArchivalBlocksResponseMessage) toAppMessage() (appmessage.Message, e
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &appmessage.GetPruningWindowRootsResponseMessage{
|
return &appmessage.AddArchivalBlocksResponseMessage{
|
||||||
Error: rpcErr,
|
Error: rpcErr,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ func (c *RPCClient) AddArchivalBlocks(blocks []*appmessage.ArchivalBlock) (*appm
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
response, err := c.route(appmessage.CmdAddArchivalBlocksRequestMessage).DequeueWithTimeout(c.timeout)
|
response, err := c.route(appmessage.CmdAddArchivalBlocksResponseMessage).DequeueWithTimeout(c.timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,11 +3,11 @@ package rpcclient
|
|||||||
import "github.com/kaspanet/kaspad/app/appmessage"
|
import "github.com/kaspanet/kaspad/app/appmessage"
|
||||||
|
|
||||||
func (c *RPCClient) GetPruningWindowRoots() (*appmessage.GetPruningWindowRootsResponseMessage, error) {
|
func (c *RPCClient) GetPruningWindowRoots() (*appmessage.GetPruningWindowRootsResponseMessage, error) {
|
||||||
err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewGetPeerAddressesRequestMessage())
|
err := c.rpcRouter.outgoingRoute().Enqueue(&appmessage.GetPruningWindowRootsRequestMessage{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
response, err := c.route(appmessage.CmdGetPruningWindowRootsRequestMessage).DequeueWithTimeout(c.timeout)
|
response, err := c.route(appmessage.CmdGetPruningWindowRootsResponseMessage).DequeueWithTimeout(c.timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user