Skip to content

Commit b38ae98

Browse files
committed
v1.1.1
2 parents 3b4fbd2 + 80e942f commit b38ae98

12 files changed

Lines changed: 139 additions & 15 deletions

File tree

config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func DefaultConfig() *Config {
3939

4040
cfg.P2P.Seeds = "25104d4b173d1047e9d1a70cdefde9e30707beb1@84.201.143.192:26656," +
4141
"1e1c6149451d2a7c1072523e49cab658080d9bd2@minter-nodes-1.mainnet.btcsecure.io:26656," +
42-
"667b26ffa9f844719a9cd73f96a49252f8bfd7df@node-1.minterdex.com:26656," +
43-
"8ee270d29cc7221a61ab4c93121efba9ba83a943@minter-node-1.rundax.com:26656"
42+
"8ee270d29cc7221a61ab4c93121efba9ba83a943@minter-node-1.rundax.com:26656," +
43+
"bab220855eb9625ea547f1ef1d11692c60a7a406@138.201.28.219:26656"
4444

4545
cfg.TxIndex = &tmConfig.TxIndexConfig{
4646
Indexer: "kv",

core/state/accounts/accounts.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/MinterTeam/minter-go-node/formula"
99
"github.com/MinterTeam/minter-go-node/rlp"
1010
"github.com/MinterTeam/minter-go-node/tree"
11+
"github.com/MinterTeam/minter-go-node/upgrades"
1112
"math/big"
1213
"sort"
1314
"sync"
@@ -176,7 +177,7 @@ func (a *Accounts) ExistsMultisig(msigAddress types.Address) bool {
176177
return false
177178
}
178179

179-
func (a *Accounts) CreateMultisig(weights []uint, addresses []types.Address, threshold uint) types.Address {
180+
func (a *Accounts) CreateMultisig(weights []uint, addresses []types.Address, threshold uint, height uint64) types.Address {
180181
msig := Multisig{
181182
Weights: weights,
182183
Threshold: threshold,
@@ -201,6 +202,10 @@ func (a *Accounts) CreateMultisig(weights []uint, addresses []types.Address, thr
201202
account.MultisigData = msig
202203
account.markDirty(account.address)
203204

205+
if height > upgrades.UpgradeBlock1 {
206+
account.isDirty = true
207+
}
208+
204209
a.setToMap(address, account)
205210

206211
return address

core/state/candidates/candidates.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ func (c *Candidates) PunishByzantineCandidate(height uint64, tmAddress types.TmA
203203
})
204204

205205
c.bus.FrozenFunds().AddFrozenFund(height+UnbondPeriod, stake.Owner, candidate.PubKey, stake.Coin, newValue)
206+
stake.setValue(big.NewInt(0))
206207
}
207208
}
208209

core/state/candidates_test.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"crypto/rand"
55
"encoding/binary"
66
eventsdb "github.com/MinterTeam/events-db"
7+
"github.com/MinterTeam/minter-go-node/core/state/candidates"
78
"github.com/MinterTeam/minter-go-node/core/types"
9+
"github.com/tendermint/tendermint/crypto/ed25519"
810
db "github.com/tendermint/tm-db"
911
"math/big"
1012
"testing"
@@ -214,6 +216,119 @@ func TestStakeSufficiency(t *testing.T) {
214216
}
215217
}
216218

219+
func TestDoubleSignPenalty(t *testing.T) {
220+
st := getState()
221+
222+
pubkey := createTestCandidate(st)
223+
224+
coin := types.GetBaseCoin()
225+
amount := big.NewInt(100)
226+
var addr types.Address
227+
binary.BigEndian.PutUint64(addr[:], 1)
228+
st.Candidates.Delegate(addr, pubkey, coin, amount, big.NewInt(0))
229+
230+
st.Candidates.RecalculateStakes(1)
231+
232+
var pk ed25519.PubKeyEd25519
233+
copy(pk[:], pubkey[:])
234+
235+
var tmAddr types.TmAddress
236+
copy(tmAddr[:], pk.Address().Bytes())
237+
238+
st.Candidates.PunishByzantineCandidate(1, tmAddr)
239+
240+
stake := st.Candidates.GetStakeValueOfAddress(pubkey, addr, coin)
241+
if stake.Cmp(big.NewInt(0)) != 0 {
242+
t.Fatalf("Stake is not correct. Expected 0, got %s", stake.String())
243+
}
244+
245+
ffs := st.FrozenFunds.GetFrozenFunds(1 + candidates.UnbondPeriod)
246+
exists := false
247+
for _, ff := range ffs.List {
248+
if ff.Address == addr {
249+
exists = true
250+
251+
newValue := big.NewInt(0).Set(amount)
252+
newValue.Mul(newValue, big.NewInt(95))
253+
newValue.Div(newValue, big.NewInt(100))
254+
newValue.Sub(newValue, ff.Value)
255+
if newValue.Cmp(big.NewInt(0)) != 0 {
256+
t.Fatalf("Wrong frozen fund value. Expected %s, got %s", newValue.String(), ff.Value.String())
257+
}
258+
}
259+
}
260+
261+
if !exists {
262+
t.Fatalf("Frozen fund not found")
263+
}
264+
}
265+
266+
func TestAbsentPenalty(t *testing.T) {
267+
st := getState()
268+
269+
pubkey := createTestCandidate(st)
270+
271+
coin := types.GetBaseCoin()
272+
amount := big.NewInt(100)
273+
var addr types.Address
274+
binary.BigEndian.PutUint64(addr[:], 1)
275+
st.Candidates.Delegate(addr, pubkey, coin, amount, big.NewInt(0))
276+
277+
st.Candidates.RecalculateStakes(1)
278+
279+
var pk ed25519.PubKeyEd25519
280+
copy(pk[:], pubkey[:])
281+
282+
var tmAddr types.TmAddress
283+
copy(tmAddr[:], pk.Address().Bytes())
284+
285+
st.Candidates.Punish(1, tmAddr)
286+
287+
stake := st.Candidates.GetStakeValueOfAddress(pubkey, addr, coin)
288+
newValue := big.NewInt(0).Set(amount)
289+
newValue.Mul(newValue, big.NewInt(99))
290+
newValue.Div(newValue, big.NewInt(100))
291+
if stake.Cmp(newValue) != 0 {
292+
t.Fatalf("Stake is not correct. Expected %s, got %s", newValue, stake.String())
293+
}
294+
}
295+
296+
func TestDoubleAbsentPenalty(t *testing.T) {
297+
st := getState()
298+
299+
pubkey := createTestCandidate(st)
300+
301+
coin := types.GetBaseCoin()
302+
amount := big.NewInt(100)
303+
var addr types.Address
304+
binary.BigEndian.PutUint64(addr[:], 1)
305+
st.Candidates.Delegate(addr, pubkey, coin, amount, big.NewInt(0))
306+
st.Candidates.SetOnline(pubkey)
307+
308+
st.Candidates.RecalculateStakes(1)
309+
310+
var pk ed25519.PubKeyEd25519
311+
copy(pk[:], pubkey[:])
312+
313+
var tmAddr types.TmAddress
314+
copy(tmAddr[:], pk.Address().Bytes())
315+
316+
st.Validators.SetNewValidators(st.Candidates.GetNewCandidates(1))
317+
318+
for i := 1000; i < 1050; i++ {
319+
st.Validators.SetValidatorAbsent(uint64(i), tmAddr)
320+
st.Validators.SetNewValidators(st.Candidates.GetNewCandidates(1))
321+
}
322+
323+
stake := st.Candidates.GetStakeValueOfAddress(pubkey, addr, coin)
324+
newValue := big.NewInt(0).Set(amount)
325+
newValue.Mul(newValue, big.NewInt(99))
326+
newValue.Div(newValue, big.NewInt(100))
327+
if stake.Cmp(newValue) != 0 {
328+
t.Fatalf("Stake is not correct. Expected %s, got %s", newValue, stake.String())
329+
}
330+
}
331+
217332
func getState() *State {
218333
s, err := NewState(0, db.NewMemDB(), emptyEvents{}, 1, 1)
219334

core/state/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (s *State) Import(state types.AppState) error {
151151

152152
for _, a := range state.Accounts {
153153
if a.MultisigData != nil {
154-
s.Accounts.CreateMultisig(a.MultisigData.Weights, a.MultisigData.Addresses, a.MultisigData.Threshold)
154+
s.Accounts.CreateMultisig(a.MultisigData.Weights, a.MultisigData.Addresses, a.MultisigData.Threshold, 1)
155155
}
156156

157157
s.Accounts.SetNonce(a.Address, a.Nonce)

core/transaction/create_multisig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (data CreateMultisigData) Run(tx *Transaction, context *state.State, isChec
163163
context.Accounts.SubBalance(sender, tx.GasCoin, commission)
164164
context.Accounts.SetNonce(sender, tx.Nonce)
165165

166-
context.Accounts.CreateMultisig(data.Weights, data.Addresses, data.Threshold)
166+
context.Accounts.CreateMultisig(data.Weights, data.Addresses, data.Threshold, currentBlock)
167167
}
168168

169169
tags := kv.Pairs{

core/transaction/create_multisig_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func TestCreateExistingMultisigTx(t *testing.T) {
233233
},
234234
}
235235

236-
cState.Accounts.CreateMultisig(data.Weights, data.Addresses, data.Threshold)
236+
cState.Accounts.CreateMultisig(data.Weights, data.Addresses, data.Threshold, 1)
237237

238238
encodedData, err := rlp.EncodeToBytes(data)
239239
if err != nil {

core/transaction/executor_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func TestMultiSigTx(t *testing.T) {
231231
addr := crypto.PubkeyToAddress(privateKey.PublicKey)
232232
coin := types.GetBaseCoin()
233233

234-
msigAddress := cState.Accounts.CreateMultisig([]uint{1}, []types.Address{addr}, 1)
234+
msigAddress := cState.Accounts.CreateMultisig([]uint{1}, []types.Address{addr}, 1, 1)
235235
cState.Accounts.AddBalance(msigAddress, coin, helpers.BipToPip(big.NewInt(1000000)))
236236

237237
txData := SendData{
@@ -275,7 +275,7 @@ func TestMultiSigDoubleSignTx(t *testing.T) {
275275
addr := crypto.PubkeyToAddress(privateKey.PublicKey)
276276
coin := types.GetBaseCoin()
277277

278-
msigAddress := cState.Accounts.CreateMultisig([]uint{1, 1}, []types.Address{addr, {}}, 2)
278+
msigAddress := cState.Accounts.CreateMultisig([]uint{1, 1}, []types.Address{addr, {}}, 2, 1)
279279
cState.Accounts.AddBalance(msigAddress, coin, helpers.BipToPip(big.NewInt(1000000)))
280280

281281
txData := SendData{
@@ -323,7 +323,7 @@ func TestMultiSigTooManySignsTx(t *testing.T) {
323323
addr := crypto.PubkeyToAddress(privateKey.PublicKey)
324324
coin := types.GetBaseCoin()
325325

326-
msigAddress := cState.Accounts.CreateMultisig([]uint{1, 1}, []types.Address{addr, {}}, 2)
326+
msigAddress := cState.Accounts.CreateMultisig([]uint{1, 1}, []types.Address{addr, {}}, 2, 1)
327327
cState.Accounts.AddBalance(msigAddress, coin, helpers.BipToPip(big.NewInt(1000000)))
328328

329329
txData := SendData{
@@ -374,7 +374,7 @@ func TestMultiSigNotEnoughTx(t *testing.T) {
374374
addr := crypto.PubkeyToAddress(privateKey.PublicKey)
375375
coin := types.GetBaseCoin()
376376

377-
msigAddress := cState.Accounts.CreateMultisig([]uint{1}, []types.Address{addr}, 2)
377+
msigAddress := cState.Accounts.CreateMultisig([]uint{1}, []types.Address{addr}, 2, 1)
378378
cState.Accounts.AddBalance(msigAddress, coin, helpers.BipToPip(big.NewInt(1000000)))
379379

380380
txData := SendData{
@@ -418,7 +418,7 @@ func TestMultiSigIncorrectSignsTx(t *testing.T) {
418418
addr := crypto.PubkeyToAddress(privateKey.PublicKey)
419419
coin := types.GetBaseCoin()
420420

421-
msigAddress := cState.Accounts.CreateMultisig([]uint{1}, []types.Address{addr}, 1)
421+
msigAddress := cState.Accounts.CreateMultisig([]uint{1}, []types.Address{addr}, 1, 1)
422422
cState.Accounts.AddBalance(msigAddress, coin, helpers.BipToPip(big.NewInt(1000000)))
423423

424424
txData := SendData{

core/transaction/send_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestSendMultisigTx(t *testing.T) {
8282

8383
coin := types.GetBaseCoin()
8484

85-
msig := cState.Accounts.CreateMultisig([]uint{1, 1}, []types.Address{addr1, addr2}, 1)
85+
msig := cState.Accounts.CreateMultisig([]uint{1, 1}, []types.Address{addr1, addr2}, 1, 1)
8686

8787
cState.Accounts.AddBalance(msig, coin, helpers.BipToPip(big.NewInt(1000000)))
8888

@@ -150,7 +150,7 @@ func TestSendFailedMultisigTx(t *testing.T) {
150150

151151
coin := types.GetBaseCoin()
152152

153-
msig := cState.Accounts.CreateMultisig([]uint{1, 3}, []types.Address{addr1, addr2}, 3)
153+
msig := cState.Accounts.CreateMultisig([]uint{1, 3}, []types.Address{addr1, addr2}, 3, 1)
154154

155155
cState.Accounts.AddBalance(msig, coin, helpers.BipToPip(big.NewInt(1000000)))
156156

upgrades/blocks.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
package upgrades
2+
3+
const UpgradeBlock1 = 0

0 commit comments

Comments
 (0)