Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Rm tx status fail (#1882)
Browse files Browse the repository at this point in the history
* feat(comment it out of test_fileter_account_utxo): comment it out of test_fileter_account_utxo

* feat(delete block_commintment transactionstatushash field): del BlockCommintment TxStatusHash

* feat(modify bc.proto): modify bc.proto

* feat(delete tx_status_root of blockheader): delete tx_status_root of blockheader

* feat(delete tx_status_test): delete tx_status_test

* feat(modify blockindex.go): modify blockindex.go

* feat(modify block_retrieve.go): modify block_retrieve.go

* feat(modify merkle.go): modify merkle.go

* feat(modify mining.go): modify mining.go

* feat(modify block_keeper_test.go): modify block_keeper_test.go

* feat(modify merkle.go): modify merkle.go

* feat(modify): modify block_retrieve.go

* feat(modify block_retrieve.go): modify block_retrieve.go

* feat(modify block_retrieve.go): modify block_retrieve.go

* feat(modify query/annotated.go): modify query/annotated.go

* feat(modify): modify

* feat(modify utxos.go): modify utxos.go

* feat(modify): modify

* feat(modify utxo.go): modify utxo.go

* feat(modify utxo_test.go): modify utxo_test.go

* feat(modify wallet.go): modify wallet.go

* feat(modify wallet.go): modify wallet.go

* feat(modify netsync message.go): modify netsync message.go

* feat(modif peer.go): modify peer.go

* feat(netsync handle.go): netsync handle.go

* feat(modify message.go): modify message.go

* feat(modify utxo_view.go): modify utxo_view.go

* feat(temp modify validationtx): temp modify ValidationTx

* feat(modify block.go): modify block.go

* feat(modify utxo_view.g): modify utxo_view.go

* feat(modify chain interface): remove GetTransactionStatus func

* feat(modify mock/chain.go): modify mock/chain.go

* feat(modify store.go): modify store.go

* feat(delete ts.getstatus): delete ts.GetStatus

* feat(modify mining.go): modify mining.go

* feat(modify store.go): modify store.go SaveBlock fn

* feat(modify protocol.go init_chain_status): modify protocol.go initChainStatus

* feat(modify block.go validate_block func): modify block.go ValidateBlock fnc

* feat(modify block_test_util.go): modify NewBlock func

* feat(modify tx_status.go): delete SetTransactionStatus func

* feat(modify tx_status.go): delete NewTransactionStatus func

* feat(modify tx_status.go): modify tx_status.go

* feat(modify bc.proto): modify bc.proto

* feat(modify blockheader.go): modify blockheader.go

* feat(modify block_retrieve.go): modify block_retrieve.go

* feat(modify txpool.go): modify txpool.go

* feat(format): format

* feat(modify block_integration_test.go): modify block_integration_test.go

* feat(modify block.go validate_block fn): modify block.go ValidateBlock fn

* feat(golint): golint

* feat(fix): fix

* feat(fix): fix

* feat(fix): fix

* feat(fix): fix

* feat(fix): fix

* feat(fix): fix

* feat(add test control): add test control

* feat(temp): temp

* feat(modify bypes/block_test.go): modify want hash

* feat(netsync/consensusmgr/consensus_msg_test.go): modify

* feat(modify): blockindex_test.go TestNewBlockNode

* feat(ignore block_process_test): ignore TestBlockProcess

* feat(modify block_integration_test.go): modify TestProcessBlock fn

* feat(golint): golint

* feat(golint): golint

* feat(rm pow_test.go): rm pow_test.go

* feat(modify block_integration_test.go): modify b

* feat(modify testcontrol): delete CHXTest

* feat(delete wallet test temp file): delete wallet temp file by test generate
  • Loading branch information
hauson authored Apr 13, 2021
1 parent 7edcc7c commit 674bf0a
Show file tree
Hide file tree
Showing 62 changed files with 445 additions and 1,284 deletions.
46 changes: 10 additions & 36 deletions api/block_retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ func (a *API) getBlockCount() Response {

// BlockTx is the tx struct for getBlock func
type BlockTx struct {
ID bc.Hash `json:"id"`
Version uint64 `json:"version"`
Size uint64 `json:"size"`
TimeRange uint64 `json:"time_range"`
Inputs []*query.AnnotatedInput `json:"inputs"`
Outputs []*query.AnnotatedOutput `json:"outputs"`
StatusFail bool `json:"status_fail"`
MuxID bc.Hash `json:"mux_id"`
ID bc.Hash `json:"id"`
Version uint64 `json:"version"`
Size uint64 `json:"size"`
TimeRange uint64 `json:"time_range"`
Inputs []*query.AnnotatedInput `json:"inputs"`
Outputs []*query.AnnotatedOutput `json:"outputs"`
MuxID bc.Hash `json:"mux_id"`
}

// BlockReq is used to handle getBlock req
Expand All @@ -48,7 +47,6 @@ type GetBlockResp struct {
PreviousBlockHash *bc.Hash `json:"previous_block_hash"`
Timestamp uint64 `json:"timestamp"`
TransactionsMerkleRoot *bc.Hash `json:"transaction_merkle_root"`
TransactionStatusHash *bc.Hash `json:"transaction_status_hash"`
Transactions []*BlockTx `json:"transactions"`
}

Expand All @@ -60,7 +58,6 @@ func (a *API) getBlock(ins BlockReq) Response {
}

blockHash := block.Hash()
txStatus, err := a.chain.GetTransactionStatus(&blockHash)
rawBlock, err := block.MarshalText()
if err != nil {
return NewErrorResponse(err)
Expand All @@ -74,11 +71,10 @@ func (a *API) getBlock(ins BlockReq) Response {
PreviousBlockHash: &block.PreviousBlockHash,
Timestamp: block.Timestamp,
TransactionsMerkleRoot: &block.TransactionsMerkleRoot,
TransactionStatusHash: &block.TransactionStatusHash,
Transactions: []*BlockTx{},
}

for i, orig := range block.Transactions {
for _, orig := range block.Transactions {
tx := &BlockTx{
ID: orig.ID,
Version: orig.Version,
Expand All @@ -87,10 +83,6 @@ func (a *API) getBlock(ins BlockReq) Response {
Inputs: []*query.AnnotatedInput{},
Outputs: []*query.AnnotatedOutput{},
}
tx.StatusFail, err = txStatus.GetStatus(i)
if err != nil {
return NewSuccessResponse(resp)
}

resOutID := orig.ResultIds[0]
resOut, ok := orig.Entries[*resOutID].(*bc.Output)
Expand All @@ -114,8 +106,7 @@ func (a *API) getBlock(ins BlockReq) Response {

// GetRawBlockResp is resp struct for getRawBlock API
type GetRawBlockResp struct {
RawBlock *types.Block `json:"raw_block"`
TransactionStatus *bc.TransactionStatus `json:"transaction_status"`
RawBlock *types.Block `json:"raw_block"`
}

func (a *API) getRawBlock(ins BlockReq) Response {
Expand All @@ -124,15 +115,8 @@ func (a *API) getRawBlock(ins BlockReq) Response {
return NewErrorResponse(err)
}

blockHash := block.Hash()
txStatus, err := a.chain.GetTransactionStatus(&blockHash)
if err != nil {
return NewErrorResponse(err)
}

resp := GetRawBlockResp{
RawBlock: block,
TransactionStatus: txStatus,
RawBlock: block,
}
return NewSuccessResponse(resp)
}
Expand Down Expand Up @@ -181,7 +165,6 @@ type MerkleBlockReq struct {
type GetMerkleBlockResp struct {
BlockHeader types.BlockHeader `json:"block_header"`
TxHashes []*bc.Hash `json:"tx_hashes"`
StatusHashes []*bc.Hash `json:"status_hashes"`
Flags []uint32 `json:"flags"`
MatchedTxIDs []*bc.Hash `json:"matched_tx_ids"`
}
Expand All @@ -205,18 +188,9 @@ func (a *API) getMerkleProof(ins MerkleBlockReq) Response {
flags[i] = uint32(flag)
}

blockHash := block.Hash()
statuses, err := a.chain.GetTransactionStatus(&blockHash)
if err != nil {
return NewErrorResponse(err)
}

statusHashes := types.GetStatusMerkleTreeProof(statuses.VerifyStatus, compactFlags)

resp := &GetMerkleBlockResp{
BlockHeader: block.BlockHeader,
TxHashes: hashes,
StatusHashes: statusHashes,
Flags: flags,
MatchedTxIDs: matchedTxIDs,
}
Expand Down
13 changes: 6 additions & 7 deletions api/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,12 @@ func (a *API) getUnconfirmedTx(ctx context.Context, filter struct {
}

tx := &BlockTx{
ID: txDesc.Tx.ID,
Version: txDesc.Tx.Version,
Size: txDesc.Tx.SerializedSize,
TimeRange: txDesc.Tx.TimeRange,
Inputs: []*query.AnnotatedInput{},
Outputs: []*query.AnnotatedOutput{},
StatusFail: txDesc.StatusFail,
ID: txDesc.Tx.ID,
Version: txDesc.Tx.Version,
Size: txDesc.Tx.SerializedSize,
TimeRange: txDesc.Tx.TimeRange,
Inputs: []*query.AnnotatedInput{},
Outputs: []*query.AnnotatedOutput{},
}

resOutID := txDesc.Tx.ResultIds[0]
Expand Down
1 change: 0 additions & 1 deletion blockchain/query/annotated.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type AnnotatedTx struct {
BlockTransactionsCount uint32 `json:"block_transactions_count,omitempty"`
Inputs []*AnnotatedInput `json:"inputs"`
Outputs []*AnnotatedOutput `json:"outputs"`
StatusFail bool `json:"status_fail"`
Size uint64 `json:"size"`
}

Expand Down
30 changes: 0 additions & 30 deletions config/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ func GenesisTx() *types.Tx {

func mainNetGenesisBlock() *types.Block {
tx := GenesisTx()
txStatus := bc.NewTransactionStatus()
if err := txStatus.SetStatus(0, false); err != nil {
log.Panicf(err.Error())
}
txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
if err != nil {
log.Panicf("fail on calc genesis tx status merkle root")
}

merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
if err != nil {
log.Panicf("fail on calc genesis tx merkel root")
Expand All @@ -51,7 +42,6 @@ func mainNetGenesisBlock() *types.Block {
Timestamp: 1524549600,
BlockCommitment: types.BlockCommitment{
TransactionsMerkleRoot: merkleRoot,
TransactionStatusHash: txStatusHash,
},
},
Transactions: []*types.Tx{tx},
Expand All @@ -61,15 +51,6 @@ func mainNetGenesisBlock() *types.Block {

func testNetGenesisBlock() *types.Block {
tx := GenesisTx()
txStatus := bc.NewTransactionStatus()
if err := txStatus.SetStatus(0, false); err != nil {
log.Panicf(err.Error())
}
txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
if err != nil {
log.Panicf("fail on calc genesis tx status merkle root")
}

merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
if err != nil {
log.Panicf("fail on calc genesis tx merkel root")
Expand All @@ -82,7 +63,6 @@ func testNetGenesisBlock() *types.Block {
Timestamp: 1528945000,
BlockCommitment: types.BlockCommitment{
TransactionsMerkleRoot: merkleRoot,
TransactionStatusHash: txStatusHash,
},
},
Transactions: []*types.Tx{tx},
Expand All @@ -92,15 +72,6 @@ func testNetGenesisBlock() *types.Block {

func soloNetGenesisBlock() *types.Block {
tx := GenesisTx()
txStatus := bc.NewTransactionStatus()
if err := txStatus.SetStatus(0, false); err != nil {
log.Panicf(err.Error())
}
txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
if err != nil {
log.Panicf("fail on calc genesis tx status merkle root")
}

merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
if err != nil {
log.Panicf("fail on calc genesis tx merkel root")
Expand All @@ -113,7 +84,6 @@ func soloNetGenesisBlock() *types.Block {
Timestamp: 1528945000,
BlockCommitment: types.BlockCommitment{
TransactionsMerkleRoot: merkleRoot,
TransactionStatusHash: txStatusHash,
},
},
Transactions: []*types.Tx{tx},
Expand Down
27 changes: 1 addition & 26 deletions database/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"time"

"github.com/golang/protobuf/proto"
log "github.com/sirupsen/logrus"
"github.com/tendermint/tmlibs/common"

Expand Down Expand Up @@ -58,10 +57,6 @@ func CalcBlockHeaderKey(height uint64, hash *bc.Hash) []byte {
return append(key, hash.Bytes()...)
}

func CalcTxStatusKey(hash *bc.Hash) []byte {
return append(TxStatusPrefix, hash.Bytes()...)
}

// GetBlockHeader return the BlockHeader by given hash
func (s *Store) GetBlockHeader(hash *bc.Hash) (*types.BlockHeader, error) {
return nil, nil
Expand Down Expand Up @@ -111,20 +106,6 @@ func (s *Store) GetTransactionsUtxo(view *state.UtxoViewpoint, txs []*bc.Tx) err
return getTransactionsUtxo(s.db, view, txs)
}

// GetTransactionStatus will return the utxo that related to the block hash
func (s *Store) GetTransactionStatus(hash *bc.Hash) (*bc.TransactionStatus, error) {
data := s.db.Get(CalcTxStatusKey(hash))
if data == nil {
return nil, errors.New("can't find the transaction status by given hash")
}

ts := &bc.TransactionStatus{}
if err := proto.Unmarshal(data, ts); err != nil {
return nil, errors.Wrap(err, "unmarshaling transaction status")
}
return ts, nil
}

// GetStoreStatus return the BlockStoreStateJSON
func (s *Store) GetStoreStatus() *protocol.BlockStoreState {
return loadBlockStoreStateJSON(s.db)
Expand Down Expand Up @@ -174,7 +155,7 @@ func (s *Store) LoadBlockIndex(stateBestHeight uint64) (*state.BlockIndex, error
}

// SaveBlock persists a new block in the protocol.
func (s *Store) SaveBlock(block *types.Block, ts *bc.TransactionStatus) error {
func (s *Store) SaveBlock(block *types.Block) error {
startTime := time.Now()
binaryBlock, err := block.MarshalText()
if err != nil {
Expand All @@ -186,16 +167,10 @@ func (s *Store) SaveBlock(block *types.Block, ts *bc.TransactionStatus) error {
return errors.Wrap(err, "Marshal block header")
}

binaryTxStatus, err := proto.Marshal(ts)
if err != nil {
return errors.Wrap(err, "marshal block transaction status")
}

blockHash := block.Hash()
batch := s.db.NewBatch()
batch.Set(CalcBlockKey(&blockHash), binaryBlock)
batch.Set(CalcBlockHeaderKey(block.Height, &blockHash), binaryBlockHeader)
batch.Set(CalcTxStatusKey(&blockHash), binaryTxStatus)
batch.Write()

log.WithFields(log.Fields{
Expand Down
27 changes: 6 additions & 21 deletions database/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ func TestLoadBlockIndex(t *testing.T) {
store := NewStore(testDB)

block := config.GenesisBlock()
txStatus := bc.NewTransactionStatus()

if err := store.SaveBlock(block, txStatus); err != nil {
if err := store.SaveBlock(block); err != nil {
t.Fatal(err)
}

for block.Height <= 128 {
preHash := block.Hash()
block.PreviousBlockHash = preHash
block.Height++
if err := store.SaveBlock(block, txStatus); err != nil {
if err := store.SaveBlock(block); err != nil {
t.Fatal(err)
}

Expand All @@ -39,7 +37,7 @@ func TestLoadBlockIndex(t *testing.T) {
}

for i := uint64(0); i < block.Height/32; i++ {
if err := store.SaveBlock(block, txStatus); err != nil {
if err := store.SaveBlock(block); err != nil {
t.Fatal(err)
}
}
Expand Down Expand Up @@ -76,10 +74,8 @@ func TestLoadBlockIndexBestHeight(t *testing.T) {

for _, c := range cases {
block := config.GenesisBlock()
txStatus := bc.NewTransactionStatus()

for i := uint64(0); i < c.blockBestHeight; i++ {
if err := store.SaveBlock(block, txStatus); err != nil {
if err := store.SaveBlock(block); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -108,12 +104,11 @@ func TestLoadBlockIndexEquals(t *testing.T) {
store := NewStore(testDB)

block := config.GenesisBlock()
txStatus := bc.NewTransactionStatus()
expectBlockIndex := state.NewBlockIndex()
var parent *state.BlockNode

for block.Height <= 100 {
if err := store.SaveBlock(block, txStatus); err != nil {
if err := store.SaveBlock(block); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -186,8 +181,7 @@ func TestSaveBlock(t *testing.T) {
store := NewStore(testDB)

block := config.GenesisBlock()
status := &bc.TransactionStatus{VerifyStatus: []*bc.TxVerifyResult{{StatusFail: true}}}
if err := store.SaveBlock(block, status); err != nil {
if err := store.SaveBlock(block); err != nil {
t.Fatal(err)
}

Expand All @@ -203,15 +197,6 @@ func TestSaveBlock(t *testing.T) {
t.Errorf("got block:%v, expect block:%v", gotBlock, block)
}

gotStatus, err := store.GetTransactionStatus(&blockHash)
if err != nil {
t.Fatal(err)
}

if !testutil.DeepEqual(status, gotStatus) {
t.Errorf("got status:%v, expect status:%v", gotStatus, status)
}

data := store.db.Get(CalcBlockHeaderKey(block.Height, &blockHash))
gotBlockHeader := types.BlockHeader{}
if err := gotBlockHeader.UnmarshalText(data); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.3 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/google/uuid v1.2.0
github.com/gorilla/websocket v1.4.2
github.com/grandcat/zeroconf v1.0.0
github.com/hashicorp/go-version v1.3.0
Expand Down
Loading

0 comments on commit 674bf0a

Please sign in to comment.