Skip to content

Commit

Permalink
Merge pull request #619 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v2.2.0
  • Loading branch information
danil-lashin authored Apr 30, 2021
2 parents 32fa8f1 + 8343c5c commit 8de5365
Show file tree
Hide file tree
Showing 24 changed files with 371 additions and 578 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [v2.2.0](https://github.com/MinterTeam/minter-go-node/tree/v2.2.0)

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v2.1.0...v2.2.0)

### Fixed

- Fix a critical bug in the exchange transaction through the pool
- Import and export for new entities
- Graceful stop of the node

## [v2.1.0](https://github.com/MinterTeam/minter-go-node/tree/v2.1.0)

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v2.0.3...v2.1.0)
Expand Down
4 changes: 2 additions & 2 deletions api/v2/service/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
var totalValidators []*tmTypes.Validator
{
_, okValidators := fields[pb.BlockField_validators]
_, okEvidence := fields[pb.BlockField_evidence]
if okValidators || okEvidence {
_, okProposer := fields[pb.BlockField_proposer]
if okValidators || okProposer {
valHeight := height - 1
if valHeight < 1 {
valHeight = 1
Expand Down
7 changes: 1 addition & 6 deletions api/v2/service/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
pb "github.com/MinterTeam/node-grpc-gateway/api_pb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"strconv"
"strings"
)

Expand All @@ -31,14 +30,10 @@ func (s *Service) Transaction(ctx context.Context, req *pb.TransactionRequest) (
sender, _ := decodedTx.Sender()

tags := make(map[string]string)
var gas int
for _, tag := range tx.TxResult.Events[0].Attributes {
key := string(tag.Key)
value := string(tag.Value)
tags[key] = value
if key == "tx.gas" {
gas, _ = strconv.Atoi(value)
}
}

cState := s.blockchain.CurrentState()
Expand All @@ -64,7 +59,7 @@ func (s *Service) Transaction(ctx context.Context, req *pb.TransactionRequest) (
Id: uint64(decodedTx.GasCoin),
Symbol: cState.Coins().GetCoin(decodedTx.GasCoin).GetFullSymbol(),
},
Gas: uint64(gas),
Gas: uint64(decodedTx.Gas()),
TypeHex: decodedTx.Type.String(),
Type: decodedTx.Type.UInt64(),
Data: dataStruct,
Expand Down
7 changes: 1 addition & 6 deletions api/v2/service/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
pb "github.com/MinterTeam/node-grpc-gateway/api_pb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"strconv"
"strings"
)

Expand Down Expand Up @@ -37,14 +36,10 @@ func (s *Service) Transactions(ctx context.Context, req *pb.TransactionsRequest)
sender, _ := decodedTx.Sender()

tags := make(map[string]string)
var gas int
for _, tag := range tx.TxResult.Events[0].Attributes {
key := string(tag.Key)
value := string(tag.Value)
tags[key] = value
if key == "tx.gas" {
gas, _ = strconv.Atoi(value)
}
}

data, err := encode(decodedTx.GetDecodedData(), cState.Coins())
Expand All @@ -64,7 +59,7 @@ func (s *Service) Transactions(ctx context.Context, req *pb.TransactionsRequest)
Id: uint64(decodedTx.GasCoin),
Symbol: cState.Coins().GetCoin(decodedTx.GasCoin).GetFullSymbol(),
},
Gas: uint64(gas),
Gas: uint64(decodedTx.Gas()),
TypeHex: decodedTx.Type.String(),
Type: decodedTx.Type.UInt64(),
Data: data,
Expand Down
296 changes: 150 additions & 146 deletions cmd/minter/cmd/export.go
Original file line number Diff line number Diff line change
@@ -1,148 +1,152 @@
package cmd

//
// import (
// "crypto/sha256"
// "encoding/json"
// "fmt"
// "github.com/MinterTeam/minter-go-node/cmd/utils"
// "github.com/MinterTeam/minter-go-node/coreV2/state"
// "github.com/spf13/cobra"
// "github.com/tendermint/go-amino"
// tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
// "github.com/tendermint/tendermint/types"
// "io"
// "log"
// "os"
// "time"
// )
//
// var (
// ExportCommand = &cobra.Command{
// Use: "export",
// Short: "Minter export command",
// RunE: export,
// }
// )
//
// const (
// genesisPath = "genesis.json"
//
// blockMaxBytes int64 = 10000000
// blockMaxGas int64 = 100000
// blockTimeIotaMs int64 = 1000
//
// evidenceMaxAgeNumBlocks = 1000
// evidenceMaxAgeDuration = 24 * time.Hour
// )
//
// func export(cmd *cobra.Command, args []string) error {
// height, err := cmd.Flags().GetUint64("height")
// if err != nil {
// log.Panicf("Cannot parse height: %s", err)
// }
// //
// // startHeight, err := cmd.Flags().GetUint64("start-height")
// // if err != nil {
// // log.Panicf("Cannot parse start-height: %s", err)
// // }
//
// chainID, err := cmd.Flags().GetString("chain-id")
// if err != nil {
// log.Panicf("Cannot parse chain id: %s", err)
// }
//
// genesisTime, err := cmd.Flags().GetDuration("genesis-time")
// if err != nil {
// log.Panicf("Cannot parse genesis time: %s", err)
// }
//
// indent, err := cmd.Flags().GetBool("indent")
// if err != nil {
// log.Panicf("Cannot parse indent: %s", err)
// }
//
// fmt.Println("Start exporting...")
//
// ldb, err := utils.NewStorage("", "").InitStateLevelDB("state", nil)
// if err != nil {
// log.Panicf("Cannot load db: %s", err)
// }
//
// currentState, err := state.NewCheckStateAtHeight(height, ldb)
// if err != nil {
// log.Panicf("Cannot new state at given height: %s", err)
// }
//
// exportTimeStart, newState := time.Now(), currentState.Export()
// fmt.Printf("State has been exported. Took %s", time.Since(exportTimeStart))
//
// initialHeight := height
//
// var jsonBytes []byte
// if indent {
// jsonBytes, err = amino.NewCodec().MarshalJSONIndent(newState, "", " ")
// } else {
// jsonBytes, err = amino.NewCodec().MarshalJSON(newState)
// }
// if err != nil {
// log.Panicf("Cannot marshal state to json: %s", err)
// }
//
// appHash := [32]byte{}
//
// // compose genesis
// genesis := types.GenesisDoc{
// GenesisTime: time.Unix(0, 0).Add(genesisTime),
// InitialHeight: int64(initialHeight),
// ChainID: chainID,
// ConsensusParams: &tmproto.ConsensusParams{
// Block: tmproto.BlockParams{
// MaxBytes: blockMaxBytes,
// MaxGas: blockMaxGas,
// TimeIotaMs: blockTimeIotaMs,
// },
// Evidence: tmproto.EvidenceParams{
// MaxAgeNumBlocks: evidenceMaxAgeNumBlocks,
// MaxAgeDuration: evidenceMaxAgeDuration,
// },
// Validator: tmproto.ValidatorParams{
// PubKeyTypes: []string{
// types.ABCIPubKeyTypeEd25519,
// },
// },
// },
// AppHash: appHash[:],
// AppState: json.RawMessage(jsonBytes),
// }
//
// err = genesis.ValidateAndComplete()
// if err != nil {
// log.Panicf("Failed to validate: %s", err)
// }
//
// if err := genesis.SaveAs(genesisPath); err != nil {
// log.Panicf("Failed to save genesis file: %s", err)
// }
//
// hash := getFileSha256Hash(genesisPath)
// fmt.Printf("\nOK\n%x\n", hash)
//
// return nil
// }
//
// func getFileSha256Hash(file string) []byte {
// f, err := os.Open(file)
// if err != nil {
// log.Fatal(err)
// }
//
// defer f.Close()
//
// h := sha256.New()
// if _, err := io.Copy(h, f); err != nil {
// log.Fatal(err)
// }
//
// return h.Sum(nil)
// }
import (
"crypto/sha256"
"encoding/json"
"github.com/MinterTeam/minter-go-node/cmd/utils"
"github.com/MinterTeam/minter-go-node/coreV2/appdb"
"github.com/MinterTeam/minter-go-node/coreV2/state"
"github.com/spf13/cobra"
"github.com/tendermint/go-amino"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/types"
"io"
"log"
"os"
"time"
)

var (
ExportCommand = &cobra.Command{
Use: "export",
Short: "Minter export command",
RunE: export,
}
)

const (
genesisPath = "genesis.json"

blockMaxBytes int64 = 10000000
blockMaxGas int64 = 100000
blockTimeIotaMs int64 = 1000

evidenceMaxAgeNumBlocks = 1000
evidenceMaxAgeDuration = 24 * time.Hour
)

func export(cmd *cobra.Command, args []string) error {
height, err := cmd.Flags().GetUint64("height")
if err != nil {
log.Panicf("Cannot parse height: %s", err)
}

chainID, err := cmd.Flags().GetString("chain-id")
if err != nil {
log.Panicf("Cannot parse chain id: %s", err)
}

genesisTime, err := cmd.Flags().GetDuration("genesis-time")
if err != nil {
log.Panicf("Cannot parse genesis time: %s", err)
}

indent, err := cmd.Flags().GetBool("indent")
if err != nil {
log.Panicf("Cannot parse indent: %s", err)
}

log.Println("Start exporting...")

homeDir, err := cmd.Flags().GetString("home-dir")
if err != nil {
return err
}
storages := utils.NewStorage(homeDir, "")

ldb, err := storages.InitStateLevelDB("data/state", nil)
if err != nil {
log.Panicf("Cannot load db: %s", err)
}

currentState, err := state.NewCheckStateAtHeight(height, ldb)
if err != nil {
log.Panicf("Cannot new state at given height: %s, last available height %d", err, appdb.NewAppDB(storages.GetMinterHome(), cfg).GetLastHeight())
}

exportTimeStart := time.Now()
appState := currentState.Export()
log.Printf("State has been exported. Took %s\n", time.Since(exportTimeStart))

if err := appState.Verify(); err != nil {
log.Fatalf("Failed to validate: %s\n", err)
}
log.Printf("Verify state OK\n")

var jsonBytes []byte
if indent {
jsonBytes, err = amino.NewCodec().MarshalJSONIndent(appState, "", " ")
} else {
jsonBytes, err = amino.NewCodec().MarshalJSON(appState)
}
if err != nil {
log.Panicf("Cannot marshal state to json: %s", err)
}
log.Printf("Marshal OK\n")

// compose genesis
genesis := types.GenesisDoc{
GenesisTime: time.Unix(0, 0).Add(genesisTime),
InitialHeight: int64(height),
ChainID: chainID,
ConsensusParams: &tmproto.ConsensusParams{
Block: tmproto.BlockParams{
MaxBytes: blockMaxBytes,
MaxGas: blockMaxGas,
TimeIotaMs: blockTimeIotaMs,
},
Evidence: tmproto.EvidenceParams{
MaxAgeNumBlocks: evidenceMaxAgeNumBlocks,
MaxAgeDuration: evidenceMaxAgeDuration,
},
Validator: tmproto.ValidatorParams{
PubKeyTypes: []string{
types.ABCIPubKeyTypeEd25519,
},
},
},
AppHash: nil,
AppState: json.RawMessage(jsonBytes),
}

err = genesis.ValidateAndComplete()
if err != nil {
log.Panicf("Failed to validate: %s", err)
}
log.Printf("Validate genesis OK\n")

if err := genesis.SaveAs(genesisPath); err != nil {
log.Panicf("Failed to save genesis file: %s", err)
}

hash := getFileSha256Hash(genesisPath)
log.Printf("Finish with sha256 hash: \n%x\n", hash)

return nil
}

func getFileSha256Hash(file string) []byte {
f, err := os.Open(file)
if err != nil {
log.Fatal(err)
}

defer f.Close()

h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
}

return h.Sum(nil)
}
Loading

0 comments on commit 8de5365

Please sign in to comment.