Skip to content

Commit

Permalink
Merge branch 'dev' into drop-p2p-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
someone235 committed Feb 6, 2022
2 parents 26274b7 + 69d90fe commit 5dadee9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
11 changes: 6 additions & 5 deletions cmd/kaspactl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ var (
)

type configFlags struct {
RPCServer string `short:"s" long:"rpcserver" description:"RPC server to connect to"`
Timeout uint64 `short:"t" long:"timeout" description:"Timeout for the request (in seconds)"`
RequestJSON string `short:"j" long:"json" description:"The request in JSON format"`
ListCommands bool `short:"l" long:"list-commands" description:"List all commands and exit"`
CommandAndParameters []string
RPCServer string `short:"s" long:"rpcserver" description:"RPC server to connect to"`
Timeout uint64 `short:"t" long:"timeout" description:"Timeout for the request (in seconds)"`
RequestJSON string `short:"j" long:"json" description:"The request in JSON format"`
ListCommands bool `short:"l" long:"list-commands" description:"List all commands and exit"`
AllowConnectionToDifferentVersions bool `short:"a" long:"allow-connection-to-different-versions" description:"Allow connections to versions different than kaspactl's version'"`
CommandAndParameters []string
config.NetworkFlags
}

Expand Down
22 changes: 12 additions & 10 deletions cmd/kaspactl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ func main() {
}
defer client.Disconnect()

kaspadMessage, err := client.Post(&protowire.KaspadMessage{Payload: &protowire.KaspadMessage_GetInfoRequest{GetInfoRequest: &protowire.GetInfoRequestMessage{}}})
if err != nil {
printErrorAndExit(fmt.Sprintf("Cannot post GetInfo message: %s", err))
}

localVersion := version.Version()
remoteVersion := kaspadMessage.GetGetInfoResponse().ServerVersion

if localVersion != remoteVersion {
printErrorAndExit(fmt.Sprintf("Server version mismatch, expect: %s, got: %s", localVersion, remoteVersion))
if !cfg.AllowConnectionToDifferentVersions {
kaspadMessage, err := client.Post(&protowire.KaspadMessage{Payload: &protowire.KaspadMessage_GetInfoRequest{GetInfoRequest: &protowire.GetInfoRequestMessage{}}})
if err != nil {
printErrorAndExit(fmt.Sprintf("Cannot post GetInfo message: %s", err))
}

localVersion := version.Version()
remoteVersion := kaspadMessage.GetGetInfoResponse().ServerVersion

if localVersion != remoteVersion {
printErrorAndExit(fmt.Sprintf("Server version mismatch, expect: %s, got: %s", localVersion, remoteVersion))
}
}

responseChan := make(chan string)
Expand Down
7 changes: 6 additions & 1 deletion domain/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ func (s *consensus) ValidateTransactionAndPopulateWithConsensusData(transaction
return err
}

err = s.transactionValidator.ValidateTransactionInContextIgnoringUTXO(stagingArea, transaction, model.VirtualBlockHash)
virtualPastMedianTime, err := s.pastMedianTimeManager.PastMedianTime(stagingArea, model.VirtualBlockHash)
if err != nil {
return err
}

err = s.transactionValidator.ValidateTransactionInContextIgnoringUTXO(stagingArea, transaction, model.VirtualBlockHash, virtualPastMedianTime)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type TransactionValidator interface {
ValidateTransactionInIsolation(transaction *externalapi.DomainTransaction) error
ValidateTransactionInContextIgnoringUTXO(stagingArea *StagingArea, tx *externalapi.DomainTransaction,
povBlockHash *externalapi.DomainHash) error
povBlockHash *externalapi.DomainHash, povBlockPastMedianTime int64) error
ValidateTransactionInContextAndPopulateFee(stagingArea *StagingArea,
tx *externalapi.DomainTransaction, povBlockHash *externalapi.DomainHash) error
PopulateMass(transaction *externalapi.DomainTransaction)
Expand Down
7 changes: 6 additions & 1 deletion domain/consensus/processes/blockbuilder/block_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ func (bb *blockBuilder) validateTransaction(
return err
}

err = bb.transactionValidator.ValidateTransactionInContextIgnoringUTXO(stagingArea, transaction, model.VirtualBlockHash)
virtualPastMedianTime, err := bb.pastMedianTimeManager.PastMedianTime(stagingArea, model.VirtualBlockHash)
if err != nil {
return err
}

err = bb.transactionValidator.ValidateTransactionInContextIgnoringUTXO(stagingArea, transaction, model.VirtualBlockHash, virtualPastMedianTime)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ func (v *blockValidator) checkBlockTransactions(
}

// Ensure all transactions in the block are finalized.
pastMedianTime, err := v.pastMedianTimeManager.PastMedianTime(stagingArea, blockHash)
if err != nil {
return err
}
for _, tx := range block.Transactions {
if err = v.transactionValidator.ValidateTransactionInContextIgnoringUTXO(stagingArea, tx, blockHash); err != nil {
if err = v.transactionValidator.ValidateTransactionInContextIgnoringUTXO(stagingArea, tx, blockHash, pastMedianTime); err != nil {
return err
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,12 @@ func (v *transactionValidator) IsFinalizedTransaction(tx *externalapi.DomainTran

// ValidateTransactionInContextIgnoringUTXO validates the transaction with consensus context but ignoring UTXO
func (v *transactionValidator) ValidateTransactionInContextIgnoringUTXO(stagingArea *model.StagingArea, tx *externalapi.DomainTransaction,
povBlockHash *externalapi.DomainHash) error {
povBlockHash *externalapi.DomainHash, povBlockPastMedianTime int64) error {

povBlockDAAScore, err := v.daaBlocksStore.DAAScore(v.databaseContext, stagingArea, povBlockHash)
if err != nil {
return err
}
povBlockPastMedianTime, err := v.pastMedianTimeManager.PastMedianTime(stagingArea, povBlockHash)
if err != nil {
return err
}
if isFinalized := v.IsFinalizedTransaction(tx, povBlockDAAScore, povBlockPastMedianTime); !isFinalized {
return errors.Wrapf(ruleerrors.ErrUnfinalizedTx, "unfinalized transaction %v", tx)
}
Expand Down

0 comments on commit 5dadee9

Please sign in to comment.