diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 7bf69325e..1d4c6de18 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -396,8 +396,12 @@ func (bc *Blockchain) notificationDispatcher() { // Close stops Blockchain's internal loop, syncs changes to persistent storage // and closes it. The Blockchain is no longer functional after the call to Close. func (bc *Blockchain) Close() { + // If there is a block addition in progress, wait for it to finish and + // don't allow new ones. + bc.addLock.Lock() close(bc.stopCh) <-bc.runToExitCh + bc.addLock.Unlock() } // AddBlock accepts successive block for the Blockchain, verifies it and diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index c4ff4f4b6..a334baa33 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -234,7 +234,7 @@ func TestCreateBasicChain(t *testing.T) { } m.ABI.EntryPoint.ReturnType = smartcontract.BoolType m.Features = smartcontract.HasStorage - bs, err := testserdes.EncodeBinary(m) + bs, err := m.MarshalJSON() require.NoError(t, err) emit.Bytes(script.BinWriter, bs) emit.Bytes(script.BinWriter, avm) diff --git a/pkg/core/interop_neo.go b/pkg/core/interop_neo.go index e27919ae5..6717c620c 100644 --- a/pkg/core/interop_neo.go +++ b/pkg/core/interop_neo.go @@ -8,7 +8,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/state" - "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" @@ -76,10 +75,9 @@ func createContractStateFromVM(ic *interop.Context, v *vm.VM) (*state.Contract, return nil, errGasLimitExceeded } var m manifest.Manifest - r := io.NewBinReaderFromBuf(manifestBytes) - m.DecodeBinary(r) - if r.Err != nil { - return nil, r.Err + err := m.UnmarshalJSON(manifestBytes) + if err != nil { + return nil, err } return &state.Contract{ Script: script, diff --git a/pkg/core/native/native_gas.go b/pkg/core/native/native_gas.go index 4d76ceac7..2e1e57ada 100644 --- a/pkg/core/native/native_gas.go +++ b/pkg/core/native/native_gas.go @@ -80,6 +80,9 @@ func (g *GAS) Initialize(ic *interop.Context) error { // OnPersist implements Contract interface. func (g *GAS) OnPersist(ic *interop.Context) error { + if len(ic.Block.Transactions) == 0 { + return nil + } for _, tx := range ic.Block.Transactions { absAmount := big.NewInt(int64(tx.SystemFee + tx.NetworkFee)) g.burn(ic, tx.Sender, absAmount) diff --git a/pkg/core/state/native_state.go b/pkg/core/state/native_state.go index d551c6711..bb1d94ebf 100644 --- a/pkg/core/state/native_state.go +++ b/pkg/core/state/native_state.go @@ -125,6 +125,7 @@ func (s *NEOBalanceState) fromStackItem(item stackitem.Item) { votes := structItem[2].Value().([]stackitem.Item) s.Votes = make([]*keys.PublicKey, len(votes)) for i, v := range votes { + s.Votes[i] = new(keys.PublicKey) s.Votes[i].DecodeBytes(v.Value().([]byte)) } } diff --git a/pkg/network/server.go b/pkg/network/server.go index befc08ef4..2127691dd 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -648,7 +648,7 @@ func (s *Server) handleTxCmd(tx *transaction.Transaction) error { func (s *Server) handleAddrCmd(p Peer, addrs *payload.AddressList) error { for _, a := range addrs.Addrs { addr, err := a.GetTCPAddress() - if err != nil { + if err == nil { s.discovery.BackFill(addr) } } diff --git a/pkg/rpc/request/txBuilder.go b/pkg/rpc/request/txBuilder.go index 7176ff7f2..a28f94d4b 100644 --- a/pkg/rpc/request/txBuilder.go +++ b/pkg/rpc/request/txBuilder.go @@ -19,9 +19,10 @@ import ( // with its metadata and system fee require for this. func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, util.Fixed8, error) { script := io.NewBufBinWriter() - w := io.NewBufBinWriter() - manif.EncodeBinary(w.BinWriter) - rawManifest := w.Bytes() + rawManifest, err := manif.MarshalJSON() + if err != nil { + return nil, 0, err + } emit.Bytes(script.BinWriter, rawManifest) emit.Bytes(script.BinWriter, avm) emit.Syscall(script.BinWriter, "System.Contract.Create") diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index a8428a642..7cd510479 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -51,7 +51,7 @@ type rpcTestCase struct { } const testContractHash = "e65ff7b3a02d207b584a5c27057d4e9862ef01da" -const deploymentTxHash = "5ce44eae362d3f81d440cb73cf4e4af71e69851bcd683b076aa08b7346d4e69b" +const deploymentTxHash = "b0428600383ec7f7b06734978a24dbe81edc87b781f58c0614f122c735d8cf6a" var rpcTestCases = map[string][]rpcTestCase{ "getapplicationlog": { @@ -148,7 +148,7 @@ var rpcTestCases = map[string][]rpcTestCase{ }, { Asset: e.chain.UtilityTokenHash(), - Amount: "923.96934740", + Amount: "923.96937740", LastUpdated: 6, }}, Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(), diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index 2a6c5f910..aa3bb8e87 100644 Binary files a/pkg/rpc/server/testdata/testblocks.acc and b/pkg/rpc/server/testdata/testblocks.acc differ