Skip to content

Commit

Permalink
Merge pull request #299 from MinterTeam/dev
Browse files Browse the repository at this point in the history
Fix multisig persistence
  • Loading branch information
danil-lashin authored Mar 6, 2020
2 parents df67cc9 + 80e942f commit 6633efc
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
7 changes: 6 additions & 1 deletion core/state/accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/MinterTeam/minter-go-node/formula"
"github.com/MinterTeam/minter-go-node/rlp"
"github.com/MinterTeam/minter-go-node/tree"
"github.com/MinterTeam/minter-go-node/upgrades"
"math/big"
"sort"
"sync"
Expand Down Expand Up @@ -176,7 +177,7 @@ func (a *Accounts) ExistsMultisig(msigAddress types.Address) bool {
return false
}

func (a *Accounts) CreateMultisig(weights []uint, addresses []types.Address, threshold uint) types.Address {
func (a *Accounts) CreateMultisig(weights []uint, addresses []types.Address, threshold uint, height uint64) types.Address {
msig := Multisig{
Weights: weights,
Threshold: threshold,
Expand All @@ -201,6 +202,10 @@ func (a *Accounts) CreateMultisig(weights []uint, addresses []types.Address, thr
account.MultisigData = msig
account.markDirty(account.address)

if height > upgrades.UpgradeBlock1 {
account.isDirty = true
}

a.setToMap(address, account)

return address
Expand Down
2 changes: 1 addition & 1 deletion core/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (s *State) Import(state types.AppState) error {

for _, a := range state.Accounts {
if a.MultisigData != nil {
s.Accounts.CreateMultisig(a.MultisigData.Weights, a.MultisigData.Addresses, a.MultisigData.Threshold)
s.Accounts.CreateMultisig(a.MultisigData.Weights, a.MultisigData.Addresses, a.MultisigData.Threshold, 1)
}

s.Accounts.SetNonce(a.Address, a.Nonce)
Expand Down
2 changes: 1 addition & 1 deletion core/transaction/create_multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (data CreateMultisigData) Run(tx *Transaction, context *state.State, isChec
context.Accounts.SubBalance(sender, tx.GasCoin, commission)
context.Accounts.SetNonce(sender, tx.Nonce)

context.Accounts.CreateMultisig(data.Weights, data.Addresses, data.Threshold)
context.Accounts.CreateMultisig(data.Weights, data.Addresses, data.Threshold, currentBlock)
}

tags := kv.Pairs{
Expand Down
2 changes: 1 addition & 1 deletion core/transaction/create_multisig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func TestCreateExistingMultisigTx(t *testing.T) {
},
}

cState.Accounts.CreateMultisig(data.Weights, data.Addresses, data.Threshold)
cState.Accounts.CreateMultisig(data.Weights, data.Addresses, data.Threshold, 1)

encodedData, err := rlp.EncodeToBytes(data)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions core/transaction/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func TestMultiSigTx(t *testing.T) {
addr := crypto.PubkeyToAddress(privateKey.PublicKey)
coin := types.GetBaseCoin()

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

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

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

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

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

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

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

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

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

txData := SendData{
Expand Down
4 changes: 2 additions & 2 deletions core/transaction/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestSendMultisigTx(t *testing.T) {

coin := types.GetBaseCoin()

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

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

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

coin := types.GetBaseCoin()

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

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

Expand Down
2 changes: 2 additions & 0 deletions upgrades/blocks.go
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package upgrades

const UpgradeBlock1 = 5000
1 change: 1 addition & 0 deletions upgrades/grace.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package upgrades

var gracePeriods = []*gracePeriod{
NewGracePeriod(1, 120),
NewGracePeriod(UpgradeBlock1, UpgradeBlock1+120),
}

type gracePeriod struct {
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (

var (
// Must be a string because scripts like dist.sh read this file.
Version = "1.1.0"
Version = "1.1.1"

// GitCommit is the current HEAD set using ldflags.
GitCommit string
Expand Down

0 comments on commit 6633efc

Please sign in to comment.