Skip to content

393 mempool rollback step backup mempool transactions into badgerdb #406

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

Merged
merged 23 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@
[[constraint]]
name = "github.com/prometheus/client_golang"
version = "1.1.0"

[[constraint]]
name = "github.com/golang/mock"
version = "1.3.1"
36 changes: 17 additions & 19 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@ import (
"net"
"net/http"

log "github.com/sirupsen/logrus"
"github.com/zoobc/zoobc-core/common/kvdb"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/zoobc/zoobc-core/common/interceptor"
"github.com/zoobc/zoobc-core/observer"

"github.com/zoobc/zoobc-core/common/chaintype"
coreService "github.com/zoobc/zoobc-core/core/service"
"github.com/zoobc/zoobc-core/p2p"

"github.com/zoobc/zoobc-core/common/crypto"
"github.com/zoobc/zoobc-core/common/transaction"

log "github.com/sirupsen/logrus"
"github.com/zoobc/zoobc-core/api/handler"
"github.com/zoobc/zoobc-core/api/service"
"github.com/zoobc/zoobc-core/common/chaintype"
"github.com/zoobc/zoobc-core/common/crypto"
"github.com/zoobc/zoobc-core/common/interceptor"
"github.com/zoobc/zoobc-core/common/kvdb"
"github.com/zoobc/zoobc-core/common/query"
rpcService "github.com/zoobc/zoobc-core/common/service"
"github.com/zoobc/zoobc-core/common/transaction"
coreService "github.com/zoobc/zoobc-core/core/service"
"github.com/zoobc/zoobc-core/observer"
"github.com/zoobc/zoobc-core/p2p"
"google.golang.org/grpc"
)

Expand All @@ -35,6 +31,9 @@ func startGrpcServer(
blockServices map[int32]coreService.BlockServiceInterface, ownerAccountAddress, nodefilePath string,
logger *log.Logger,
) {

chainType := chaintype.GetChainType(0)

grpcServer := grpc.NewServer(
grpc.UnaryInterceptor(interceptor.NewServerInterceptor(logger, ownerAccountAddress)),
grpc.StreamInterceptor(interceptor.NewStreamInterceptor(ownerAccountAddress)),
Expand All @@ -43,15 +42,15 @@ func startGrpcServer(
Executor: queryExecutor,
}
mempoolService := coreService.NewMempoolService(
&chaintype.MainChain{},
kvExecutor,
chainType, kvExecutor,
queryExecutor,
query.NewMempoolQuery(&chaintype.MainChain{}),
query.NewMempoolQuery(chainType),
query.NewMerkleTreeQuery(),
actionTypeSwitcher,
query.NewAccountBalanceQuery(),
query.NewBlockQuery(chainType),
query.NewTransactionQuery(chainType),
crypto.NewSignature(),
query.NewTransactionQuery(&chaintype.MainChain{}),
observer.NewObserver(),
logger,
)
Expand All @@ -71,8 +70,7 @@ func startGrpcServer(
// Set GRPC handler for Transactions requests
rpcService.RegisterTransactionServiceServer(grpcServer, &handler.TransactionHandler{
Service: service.NewTransactionService(
queryExecutor,
crypto.NewSignature(),
queryExecutor, crypto.NewSignature(),
actionTypeSwitcher,
mempoolService,
observer.NewObserver(),
Expand Down
4 changes: 3 additions & 1 deletion api/service/mempoolTransactionApiService_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestNewMempoolTransactionsService(t *testing.T) {
want *MempoolTransactionService
}{
{
name: "NewMempoolTranscationService",
name: "NewMempoolTransactionService",
args: args{
queryExecutor: &query.Executor{},
},
Expand Down Expand Up @@ -72,6 +72,7 @@ func (*mockQueryExecutorGetMempoolTXs) ExecuteSelect(qStr string, tx bool, args
WillReturnRows(sqlmock.NewRows(query.NewMempoolQuery(&chaintype.MainChain{}).Fields).
AddRow(
1,
0,
1,
1000,
make([]byte, 88),
Expand Down Expand Up @@ -215,6 +216,7 @@ func (*mockQueryExecutorGetMempoolTXSuccess) ExecuteSelectRow(qStr string, args
mock.ExpectQuery(regexp.QuoteMeta(qStr)).
WillReturnRows(sqlmock.NewRows(query.NewMempoolQuery(&chaintype.MainChain{}).Fields).AddRow(
1,
0,
1,
1000,
make([]byte, 88),
Expand Down
9 changes: 7 additions & 2 deletions api/service/transactionApiService_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,13 @@ func TestNewTransactionService(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewTransactionService(query.NewQueryExecutor(db),
nil, nil, nil, nil); !reflect.DeepEqual(got, tt.want) {
if got := NewTransactionService(
query.NewQueryExecutor(db),
nil,
nil,
nil,
nil,
); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewTransactionService() = %v, want %v", got, tt.want)
}
defer resetTransactionService()
Expand Down
3 changes: 2 additions & 1 deletion cmd/block/blockGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ func initialize(
query.NewMerkleTreeQuery(),
actionSwitcher,
query.NewAccountBalanceQuery(),
crypto.NewSignature(),
query.NewBlockQuery(chainType),
query.NewTransactionQuery(chainType),
crypto.NewSignature(),
observerInstance,
log.New(),
)
Expand Down
4 changes: 4 additions & 0 deletions cmd/transaction/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"strings"
"time"

"github.com/zoobc/zoobc-core/common/chaintype"
"github.com/zoobc/zoobc-core/common/constant"
Expand Down Expand Up @@ -246,6 +247,9 @@ func GenerateBasicTransaction(senderSeed string,
recipientAccountAddress string,
) *model.Transaction {
senderAccountAddress := util.GetAddressFromSeed(senderSeed)
if timestamp <= 0 {
timestamp = time.Now().Unix()
}
return &model.Transaction{
Version: version,
Timestamp: timestamp,
Expand Down
1 change: 1 addition & 0 deletions common/blocker/blocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type (

var (
DBErr TypeBlocker = "DBErr"
DBRowNotFound TypeBlocker = "DBRowNotFound"
BlockErr TypeBlocker = "BlockErr"
BlockNotFoundErr TypeBlocker = "BlockNotFoundErr"
RequestParameterErr TypeBlocker = "RequestParameterErr"
Expand Down
6 changes: 5 additions & 1 deletion common/constant/kvdb.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package constant

import "time"

var (
KVdbExpiryReceiptReminder = 43200 // one month adjust later
KVdbTableBlockReminderKey = "block_reminder_"
KVdbTableTransactionReminderKey = "transaction_reminder_"
KVdbExpiryReceiptReminder = 43200 // one month adjust later
KVDBMempoolsBackup = "mempools_backup"
KVDBMempoolsBackupExpiry = 60 * time.Minute
)
4 changes: 4 additions & 0 deletions common/database/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ func (m *Migration) Init() error {
"blocksmith_index" INTEGER
)
`,
`
ALTER TABLE "mempool"
ADD COLUMN "block_height" INTEGER AFTER "id"
`,
}
return nil
}
Expand Down
91 changes: 91 additions & 0 deletions common/kvdb/kvdbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading