Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fix broken consensus tests on main branch - mocking StoreBlock in persistence module #259

Merged
merged 8 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion consensus/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package consensus

import (
"encoding/hex"
"github.com/pokt-network/pocket/shared/codec"
"unsafe"

"github.com/pokt-network/pocket/shared/codec"

typesCons "github.com/pokt-network/pocket/consensus/types"
)

Expand Down
5 changes: 3 additions & 2 deletions consensus/consensus_tests/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ loop:
func basePersistenceMock(t *testing.T, _ modules.EventsChannel) *modulesMock.MockPersistenceModule {
ctrl := gomock.NewController(t)
persistenceMock := modulesMock.NewMockPersistenceModule(ctrl)
persistenceContextMock := modulesMock.NewMockPersistenceReadContext(ctrl)
persistenceContextMock := modulesMock.NewMockPersistenceRWContext(ctrl)

persistenceMock.EXPECT().Start().Do(func() {}).AnyTimes()
persistenceMock.EXPECT().SetBus(gomock.Any()).Do(func(modules.Bus) {}).AnyTimes()
Expand Down Expand Up @@ -369,9 +369,10 @@ func baseUtilityMock(t *testing.T, _ modules.EventsChannel) *modulesMock.MockUti
ApplyBlock(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(appHash, nil).
AnyTimes()
utilityContextMock.EXPECT().StoreBlock(gomock.Any()).AnyTimes().Return(nil)

persistenceContextMock.EXPECT().Commit().Return(nil).AnyTimes()
persistenceContextMock.EXPECT().StoreBlock(gomock.Any()).AnyTimes().Return(nil)
persistenceContextMock.EXPECT().InsertBlock(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil)

return utilityMock
}
Expand Down
1 change: 0 additions & 1 deletion shared/modules/utility_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type UtilityContext interface {
// Block operations
GetProposalTransactions(proposer []byte, maxTransactionBytes int, lastBlockByzantineValidators [][]byte) (transactions [][]byte, err error)
ApplyBlock(height int64, proposer []byte, transactions [][]byte, lastBlockByzantineValidators [][]byte) (appHash []byte, err error)
StoreBlock(blockProtoBytes []byte) error

// Context operations
ReleaseContext()
Expand Down
27 changes: 1 addition & 26 deletions utility/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package utility
import (
"math/big"

typesCons "github.com/pokt-network/pocket/consensus/types" // TODO (andrew) importing consensus and persistence in this file?
// TODO(andrew): importing persistence in this file?
typesGenesis "github.com/pokt-network/pocket/persistence/types"
"github.com/pokt-network/pocket/shared/modules"

typesUtil "github.com/pokt-network/pocket/utility/types"
)

Expand Down Expand Up @@ -281,27 +280,3 @@ func (u *UtilityContext) SetValidatorMissedBlocks(address []byte, missedBlocks i
}
return nil
}

func (u *UtilityContext) StoreBlock(blockProtoBytes []byte) error {
store := u.Store()

// Store in KV Store
if err := store.StoreBlock(blockProtoBytes); err != nil {
return err
}

// Store in SQL Store
// OPTIMIZE: Ideally we'd pass in the block proto struct to utility so we don't
// have to unmarshal it here, but that's a major design decision for the interfaces.
codec := u.Codec()
block := &typesCons.Block{}
if err := codec.Unmarshal(blockProtoBytes, block); err != nil {
return typesUtil.ErrProtoUnmarshal(err)
}
header := block.BlockHeader
if err := store.InsertBlock(uint64(header.Height), header.Hash, header.ProposerAddress, header.QuorumCertificate); err != nil {
return err
}

return nil
}
15 changes: 11 additions & 4 deletions utility/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.4] - 2022-09-23
## [0.0.0.6] - 2022-09-29

- Remove unused `StoreBlock` function from the utility module interface

## [0.0.0.5] - 2022-09-23

- Created `UtilityConfig`
- Added `max_mempool_transaction_bytes` and `max_mempool_transactions` to the utility
- Added `max_mempool_transaction_bytes` and `max_mempool_transactions` to the utility
config to allow dynamic configuration of the mempool
- Matched configuration unmarshalling pattern of other modules
- Added V0 mempool default configurations
- Regenerated build files with new mempool config

## [0.0.0.4] - 2022-09-21

- Removed no-op `DeleteActor` code
- Improved unit test for `UnstakeActorsThatAreReady()`
- Removed all usages of `fmt.Sprintf()` from the testing package
- Replaced all usages of `requre.True/require.False` with `require.Equal` unless checking a boolean
- Added helper function for getting height and store for a readable and consistent `typesUtil.Error` value
- Added testing.M argument to `newTestingPersistenceModule`
- Moved in-function *literal* arguments for `newTestingPersistenceModule` to private constants
- Moved in-function _literal_ arguments for `newTestingPersistenceModule` to private constants
- Added the address parameter to `ErrInsufficientFunds` function for easier debugging
- Added unit test for `LegacyVote.ValidateBasic()`
- Added `ErrUnknownActorType` to all switch statements on `actorType`
- Removed `import` of `consTypes` (consensus module)


## [0.0.0.3] - 2022-09-15

### Code cleanup
Expand Down