Skip to content

Commit 8de5365

Browse files
authored
Merge pull request #619 from MinterTeam/dev
v2.2.0
2 parents 32fa8f1 + 8343c5c commit 8de5365

24 files changed

Lines changed: 371 additions & 578 deletions

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## [v2.2.0](https://github.com/MinterTeam/minter-go-node/tree/v2.2.0)
4+
5+
[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v2.1.0...v2.2.0)
6+
7+
### Fixed
8+
9+
- Fix a critical bug in the exchange transaction through the pool
10+
- Import and export for new entities
11+
- Graceful stop of the node
12+
313
## [v2.1.0](https://github.com/MinterTeam/minter-go-node/tree/v2.1.0)
414

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

api/v2/service/block.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
4949
var totalValidators []*tmTypes.Validator
5050
{
5151
_, okValidators := fields[pb.BlockField_validators]
52-
_, okEvidence := fields[pb.BlockField_evidence]
53-
if okValidators || okEvidence {
52+
_, okProposer := fields[pb.BlockField_proposer]
53+
if okValidators || okProposer {
5454
valHeight := height - 1
5555
if valHeight < 1 {
5656
valHeight = 1

api/v2/service/transaction.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
pb "github.com/MinterTeam/node-grpc-gateway/api_pb"
99
"google.golang.org/grpc/codes"
1010
"google.golang.org/grpc/status"
11-
"strconv"
1211
"strings"
1312
)
1413

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

3332
tags := make(map[string]string)
34-
var gas int
3533
for _, tag := range tx.TxResult.Events[0].Attributes {
3634
key := string(tag.Key)
3735
value := string(tag.Value)
3836
tags[key] = value
39-
if key == "tx.gas" {
40-
gas, _ = strconv.Atoi(value)
41-
}
4237
}
4338

4439
cState := s.blockchain.CurrentState()
@@ -64,7 +59,7 @@ func (s *Service) Transaction(ctx context.Context, req *pb.TransactionRequest) (
6459
Id: uint64(decodedTx.GasCoin),
6560
Symbol: cState.Coins().GetCoin(decodedTx.GasCoin).GetFullSymbol(),
6661
},
67-
Gas: uint64(gas),
62+
Gas: uint64(decodedTx.Gas()),
6863
TypeHex: decodedTx.Type.String(),
6964
Type: decodedTx.Type.UInt64(),
7065
Data: dataStruct,

api/v2/service/transactions.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
pb "github.com/MinterTeam/node-grpc-gateway/api_pb"
99
"google.golang.org/grpc/codes"
1010
"google.golang.org/grpc/status"
11-
"strconv"
1211
"strings"
1312
)
1413

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

3938
tags := make(map[string]string)
40-
var gas int
4139
for _, tag := range tx.TxResult.Events[0].Attributes {
4240
key := string(tag.Key)
4341
value := string(tag.Value)
4442
tags[key] = value
45-
if key == "tx.gas" {
46-
gas, _ = strconv.Atoi(value)
47-
}
4843
}
4944

5045
data, err := encode(decodedTx.GetDecodedData(), cState.Coins())
@@ -64,7 +59,7 @@ func (s *Service) Transactions(ctx context.Context, req *pb.TransactionsRequest)
6459
Id: uint64(decodedTx.GasCoin),
6560
Symbol: cState.Coins().GetCoin(decodedTx.GasCoin).GetFullSymbol(),
6661
},
67-
Gas: uint64(gas),
62+
Gas: uint64(decodedTx.Gas()),
6863
TypeHex: decodedTx.Type.String(),
6964
Type: decodedTx.Type.UInt64(),
7065
Data: data,

cmd/minter/cmd/export.go

Lines changed: 150 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,152 @@
11
package cmd
22

3-
//
4-
// import (
5-
// "crypto/sha256"
6-
// "encoding/json"
7-
// "fmt"
8-
// "github.com/MinterTeam/minter-go-node/cmd/utils"
9-
// "github.com/MinterTeam/minter-go-node/coreV2/state"
10-
// "github.com/spf13/cobra"
11-
// "github.com/tendermint/go-amino"
12-
// tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
13-
// "github.com/tendermint/tendermint/types"
14-
// "io"
15-
// "log"
16-
// "os"
17-
// "time"
18-
// )
19-
//
20-
// var (
21-
// ExportCommand = &cobra.Command{
22-
// Use: "export",
23-
// Short: "Minter export command",
24-
// RunE: export,
25-
// }
26-
// )
27-
//
28-
// const (
29-
// genesisPath = "genesis.json"
30-
//
31-
// blockMaxBytes int64 = 10000000
32-
// blockMaxGas int64 = 100000
33-
// blockTimeIotaMs int64 = 1000
34-
//
35-
// evidenceMaxAgeNumBlocks = 1000
36-
// evidenceMaxAgeDuration = 24 * time.Hour
37-
// )
38-
//
39-
// func export(cmd *cobra.Command, args []string) error {
40-
// height, err := cmd.Flags().GetUint64("height")
41-
// if err != nil {
42-
// log.Panicf("Cannot parse height: %s", err)
43-
// }
44-
// //
45-
// // startHeight, err := cmd.Flags().GetUint64("start-height")
46-
// // if err != nil {
47-
// // log.Panicf("Cannot parse start-height: %s", err)
48-
// // }
49-
//
50-
// chainID, err := cmd.Flags().GetString("chain-id")
51-
// if err != nil {
52-
// log.Panicf("Cannot parse chain id: %s", err)
53-
// }
54-
//
55-
// genesisTime, err := cmd.Flags().GetDuration("genesis-time")
56-
// if err != nil {
57-
// log.Panicf("Cannot parse genesis time: %s", err)
58-
// }
59-
//
60-
// indent, err := cmd.Flags().GetBool("indent")
61-
// if err != nil {
62-
// log.Panicf("Cannot parse indent: %s", err)
63-
// }
64-
//
65-
// fmt.Println("Start exporting...")
66-
//
67-
// ldb, err := utils.NewStorage("", "").InitStateLevelDB("state", nil)
68-
// if err != nil {
69-
// log.Panicf("Cannot load db: %s", err)
70-
// }
71-
//
72-
// currentState, err := state.NewCheckStateAtHeight(height, ldb)
73-
// if err != nil {
74-
// log.Panicf("Cannot new state at given height: %s", err)
75-
// }
76-
//
77-
// exportTimeStart, newState := time.Now(), currentState.Export()
78-
// fmt.Printf("State has been exported. Took %s", time.Since(exportTimeStart))
79-
//
80-
// initialHeight := height
81-
//
82-
// var jsonBytes []byte
83-
// if indent {
84-
// jsonBytes, err = amino.NewCodec().MarshalJSONIndent(newState, "", " ")
85-
// } else {
86-
// jsonBytes, err = amino.NewCodec().MarshalJSON(newState)
87-
// }
88-
// if err != nil {
89-
// log.Panicf("Cannot marshal state to json: %s", err)
90-
// }
91-
//
92-
// appHash := [32]byte{}
93-
//
94-
// // compose genesis
95-
// genesis := types.GenesisDoc{
96-
// GenesisTime: time.Unix(0, 0).Add(genesisTime),
97-
// InitialHeight: int64(initialHeight),
98-
// ChainID: chainID,
99-
// ConsensusParams: &tmproto.ConsensusParams{
100-
// Block: tmproto.BlockParams{
101-
// MaxBytes: blockMaxBytes,
102-
// MaxGas: blockMaxGas,
103-
// TimeIotaMs: blockTimeIotaMs,
104-
// },
105-
// Evidence: tmproto.EvidenceParams{
106-
// MaxAgeNumBlocks: evidenceMaxAgeNumBlocks,
107-
// MaxAgeDuration: evidenceMaxAgeDuration,
108-
// },
109-
// Validator: tmproto.ValidatorParams{
110-
// PubKeyTypes: []string{
111-
// types.ABCIPubKeyTypeEd25519,
112-
// },
113-
// },
114-
// },
115-
// AppHash: appHash[:],
116-
// AppState: json.RawMessage(jsonBytes),
117-
// }
118-
//
119-
// err = genesis.ValidateAndComplete()
120-
// if err != nil {
121-
// log.Panicf("Failed to validate: %s", err)
122-
// }
123-
//
124-
// if err := genesis.SaveAs(genesisPath); err != nil {
125-
// log.Panicf("Failed to save genesis file: %s", err)
126-
// }
127-
//
128-
// hash := getFileSha256Hash(genesisPath)
129-
// fmt.Printf("\nOK\n%x\n", hash)
130-
//
131-
// return nil
132-
// }
133-
//
134-
// func getFileSha256Hash(file string) []byte {
135-
// f, err := os.Open(file)
136-
// if err != nil {
137-
// log.Fatal(err)
138-
// }
139-
//
140-
// defer f.Close()
141-
//
142-
// h := sha256.New()
143-
// if _, err := io.Copy(h, f); err != nil {
144-
// log.Fatal(err)
145-
// }
146-
//
147-
// return h.Sum(nil)
148-
// }
3+
import (
4+
"crypto/sha256"
5+
"encoding/json"
6+
"github.com/MinterTeam/minter-go-node/cmd/utils"
7+
"github.com/MinterTeam/minter-go-node/coreV2/appdb"
8+
"github.com/MinterTeam/minter-go-node/coreV2/state"
9+
"github.com/spf13/cobra"
10+
"github.com/tendermint/go-amino"
11+
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
12+
"github.com/tendermint/tendermint/types"
13+
"io"
14+
"log"
15+
"os"
16+
"time"
17+
)
18+
19+
var (
20+
ExportCommand = &cobra.Command{
21+
Use: "export",
22+
Short: "Minter export command",
23+
RunE: export,
24+
}
25+
)
26+
27+
const (
28+
genesisPath = "genesis.json"
29+
30+
blockMaxBytes int64 = 10000000
31+
blockMaxGas int64 = 100000
32+
blockTimeIotaMs int64 = 1000
33+
34+
evidenceMaxAgeNumBlocks = 1000
35+
evidenceMaxAgeDuration = 24 * time.Hour
36+
)
37+
38+
func export(cmd *cobra.Command, args []string) error {
39+
height, err := cmd.Flags().GetUint64("height")
40+
if err != nil {
41+
log.Panicf("Cannot parse height: %s", err)
42+
}
43+
44+
chainID, err := cmd.Flags().GetString("chain-id")
45+
if err != nil {
46+
log.Panicf("Cannot parse chain id: %s", err)
47+
}
48+
49+
genesisTime, err := cmd.Flags().GetDuration("genesis-time")
50+
if err != nil {
51+
log.Panicf("Cannot parse genesis time: %s", err)
52+
}
53+
54+
indent, err := cmd.Flags().GetBool("indent")
55+
if err != nil {
56+
log.Panicf("Cannot parse indent: %s", err)
57+
}
58+
59+
log.Println("Start exporting...")
60+
61+
homeDir, err := cmd.Flags().GetString("home-dir")
62+
if err != nil {
63+
return err
64+
}
65+
storages := utils.NewStorage(homeDir, "")
66+
67+
ldb, err := storages.InitStateLevelDB("data/state", nil)
68+
if err != nil {
69+
log.Panicf("Cannot load db: %s", err)
70+
}
71+
72+
currentState, err := state.NewCheckStateAtHeight(height, ldb)
73+
if err != nil {
74+
log.Panicf("Cannot new state at given height: %s, last available height %d", err, appdb.NewAppDB(storages.GetMinterHome(), cfg).GetLastHeight())
75+
}
76+
77+
exportTimeStart := time.Now()
78+
appState := currentState.Export()
79+
log.Printf("State has been exported. Took %s\n", time.Since(exportTimeStart))
80+
81+
if err := appState.Verify(); err != nil {
82+
log.Fatalf("Failed to validate: %s\n", err)
83+
}
84+
log.Printf("Verify state OK\n")
85+
86+
var jsonBytes []byte
87+
if indent {
88+
jsonBytes, err = amino.NewCodec().MarshalJSONIndent(appState, "", " ")
89+
} else {
90+
jsonBytes, err = amino.NewCodec().MarshalJSON(appState)
91+
}
92+
if err != nil {
93+
log.Panicf("Cannot marshal state to json: %s", err)
94+
}
95+
log.Printf("Marshal OK\n")
96+
97+
// compose genesis
98+
genesis := types.GenesisDoc{
99+
GenesisTime: time.Unix(0, 0).Add(genesisTime),
100+
InitialHeight: int64(height),
101+
ChainID: chainID,
102+
ConsensusParams: &tmproto.ConsensusParams{
103+
Block: tmproto.BlockParams{
104+
MaxBytes: blockMaxBytes,
105+
MaxGas: blockMaxGas,
106+
TimeIotaMs: blockTimeIotaMs,
107+
},
108+
Evidence: tmproto.EvidenceParams{
109+
MaxAgeNumBlocks: evidenceMaxAgeNumBlocks,
110+
MaxAgeDuration: evidenceMaxAgeDuration,
111+
},
112+
Validator: tmproto.ValidatorParams{
113+
PubKeyTypes: []string{
114+
types.ABCIPubKeyTypeEd25519,
115+
},
116+
},
117+
},
118+
AppHash: nil,
119+
AppState: json.RawMessage(jsonBytes),
120+
}
121+
122+
err = genesis.ValidateAndComplete()
123+
if err != nil {
124+
log.Panicf("Failed to validate: %s", err)
125+
}
126+
log.Printf("Validate genesis OK\n")
127+
128+
if err := genesis.SaveAs(genesisPath); err != nil {
129+
log.Panicf("Failed to save genesis file: %s", err)
130+
}
131+
132+
hash := getFileSha256Hash(genesisPath)
133+
log.Printf("Finish with sha256 hash: \n%x\n", hash)
134+
135+
return nil
136+
}
137+
138+
func getFileSha256Hash(file string) []byte {
139+
f, err := os.Open(file)
140+
if err != nil {
141+
log.Fatal(err)
142+
}
143+
144+
defer f.Close()
145+
146+
h := sha256.New()
147+
if _, err := io.Copy(h, f); err != nil {
148+
log.Fatal(err)
149+
}
150+
151+
return h.Sum(nil)
152+
}

0 commit comments

Comments
 (0)