Skip to content

Commit

Permalink
Merge branch 'ride-v8' into ride-v8-replace-by-index
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykiselev committed Dec 16, 2023
2 parents bca0c90 + df509ef commit 35c0265
Show file tree
Hide file tree
Showing 60 changed files with 2,621 additions and 535 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -54,7 +54,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -68,4 +68,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
run: make itest

- name: Upload itest logs
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
name: itest_logs
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# with '-no-fail' we let the report trigger content trigger a failure using the GitHub Security features.
args: "-no-fail -fmt sarif -out gosec.sarif ./..."
- name: Upload SARIF file for GitHub Advanced Security Dashboard
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: gosec.sarif

Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
fi
EOF
- name: Upload SARIF file for GitHub Advanced Security Dashboard
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: semgrep.sarif

Expand Down
8 changes: 4 additions & 4 deletions cmd/statehash/statehash.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func run() error {
zap.S().Errorf("Failed to get remote state hash at height 1: %v", err)
return err
}
lsh, err := st.StateHashAtHeight(1)
lsh, err := st.LegacyStateHashAtHeight(1)
if err != nil {
zap.S().Errorf("Failed to get local state hash at 1: %v", err)
return err
Expand All @@ -156,7 +156,7 @@ func run() error {
}
height = h
}
lsh, err := st.StateHashAtHeight(height)
lsh, err := st.LegacyStateHashAtHeight(height)
if err != nil {
zap.S().Errorf("Failed to get state hash at %d: %v", height, err)
return err
Expand All @@ -178,7 +178,7 @@ func run() error {
return err
}
zap.S().Infof("State hashes are equal at height %d", h)
lsh, err = st.StateHashAtHeight(h + 1)
lsh, err = st.LegacyStateHashAtHeight(h + 1)
if err != nil {
zap.S().Errorf("Failed to get state hash at %d: %v", h+1, err)
return err
Expand All @@ -205,7 +205,7 @@ func findLastEqualStateHashes(c *client.Client, st state.State, stop uint64) (ui
var start uint64 = 1
for start <= stop {
middle := (start + stop) / 2
lsh, err = st.StateHashAtHeight(middle)
lsh, err = st.LegacyStateHashAtHeight(middle)
if err != nil {
return middle, err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/metamask/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ func (s RPCService) Eth_EstimateGas(req estimateGasRequest) (string, error) {
}
}

txKind, err := proto.GuessEthereumTransactionKind(data)
txKind, err := proto.GuessEthereumTransactionKindType(data)
if err != nil {
return "", errors.Errorf("failed to guess ethereum tx kind, %v", err)
}
switch txKind {
case proto.EthereumTransferWavesKind:
case proto.EthereumTransferWavesKindType:
return uint64ToHexString(proto.MinFee), nil
case proto.EthereumTransferAssetsKind:
case proto.EthereumTransferAssetsKindType:
fee := proto.MinFee
assetID := (*proto.AssetID)(req.To)

Expand All @@ -191,7 +191,7 @@ func (s RPCService) Eth_EstimateGas(req estimateGasRequest) (string, error) {
fee += proto.MinFeeScriptedAsset
}
return uint64ToHexString(uint64(fee)), nil
case proto.EthereumInvokeKind:
case proto.EthereumInvokeKindType:
return uint64ToHexString(proto.MinFeeInvokeScript), nil
default:
return "", errors.Errorf("unexpected ethereum tx kind")
Expand Down
25 changes: 24 additions & 1 deletion pkg/api/node_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ func (a *NodeApi) nodeProcesses(w http.ResponseWriter, _ *http.Request) error {
}

func (a *NodeApi) stateHashDebug(height proto.Height) (*proto.StateHashDebug, error) {
stateHash, err := a.state.StateHashAtHeight(height)
stateHash, err := a.state.LegacyStateHashAtHeight(height)
if err != nil {
return nil, errors.Wrapf(err, "failed to get state hash at height %d", height)
}
Expand Down Expand Up @@ -805,6 +805,29 @@ func (a *NodeApi) stateHashLast(w http.ResponseWriter, _ *http.Request) error {
return nil
}

func (a *NodeApi) snapshotStateHash(w http.ResponseWriter, r *http.Request) error {
s := chi.URLParam(r, "height")
height, err := strconv.ParseUint(s, 10, 64)
if err != nil {
// TODO(nickeskov): which error it should send?
return &BadRequestError{err}
}
sh, err := a.state.SnapshotStateHashAtHeight(height)
if err != nil {
if state.IsNotFound(err) {
return apiErrs.BlockDoesNotExist
}
return errors.Wrapf(err, "failed to get snapshot state hash at height %d", height)
}
type out struct {
StateHash proto.HexBytes `json:"stateHash"`
}
if sendErr := trySendJson(w, out{StateHash: sh.Bytes()}); sendErr != nil {
return errors.Wrap(sendErr, "snapshotStateHash")
}
return nil
}

func wavesAddressInvalidCharErr(invalidChar rune, id string) *apiErrs.CustomValidationError {
return apiErrs.NewCustomValidationError(
fmt.Sprintf(
Expand Down
6 changes: 5 additions & 1 deletion pkg/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"github.com/go-chi/chi/middleware"
"github.com/pkg/errors"
"github.com/semrush/zenrpc/v2"
"github.com/wavesplatform/gowaves/pkg/api/metamask"
"go.uber.org/zap"

"github.com/wavesplatform/gowaves/pkg/api/metamask"
)

type HandleErrorFunc func(w http.ResponseWriter, r *http.Request, err error)
Expand Down Expand Up @@ -88,6 +89,9 @@ func (a *NodeApi) routes(opts *RunOptions) (chi.Router, error) {

rAuth.Post("/load", wrapper(WalletLoadKeys(a.app)))
})
r.Route("/debug", func(r chi.Router) {
r.Get("/snapshotStateHash/{height:\\d+}", wrapper(a.snapshotStateHash))
})

r.Get("/miner/info", wrapper(a.GoMinerInfo))
r.Get("/node/processes", wrapper(a.nodeProcesses))
Expand Down
88 changes: 59 additions & 29 deletions pkg/mock/state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions pkg/proto/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"io"
"math"
"strings"
"time"
Expand All @@ -13,6 +14,27 @@ import (

var ErrNotFound = errors.New("not found")

// WriteBool writes the bool to the writer.
func WriteBool(w io.Writer, b bool) error {
var c byte
if b {
c = 1
} else {
c = 0
}
return WriteByte(w, c)
}

// WriteByte writes the byte to the writer.
func WriteByte(w io.Writer, c byte) error {
if bw, ok := w.(io.ByteWriter); ok {
return bw.WriteByte(c)
}
data := [...]byte{c}
_, err := w.Write(data[:])
return err
}

// PutStringWithUInt8Len converts the string to slice of bytes. The first byte of resulting slice contains the length of the string.
func PutStringWithUInt8Len(buf []byte, s string) {
sl := uint8(len(s))
Expand Down Expand Up @@ -42,6 +64,23 @@ func PutStringWithUInt16Len(buf []byte, s string) {
copy(buf[2:], s)
}

// WriteStringWithUInt16Len writes given data with 2 bytes of its length.
func WriteStringWithUInt16Len(w io.Writer, data string) error {
l := len(data)
if l > math.MaxInt16 {
return errors.Errorf("invalid data length %d", l)
}
var size [uint16Size]byte
binary.BigEndian.PutUint16(size[:], uint16(l))
if _, err := w.Write(size[:]); err != nil {
return errors.Wrap(err, "failed to write uin16 data size")
}
if _, err := io.WriteString(w, data); err != nil {
return errors.Wrap(err, "failed to write data")
}
return nil
}

// StringWithUInt16Len reads a string from the buffer `buf`.
func StringWithUInt16Len(buf []byte) (string, error) {
if l := len(buf); l < 2 {
Expand Down Expand Up @@ -91,6 +130,23 @@ func PutBytesWithUInt16Len(buf []byte, data []byte) error {
return nil
}

// WriteBytesWithUInt16Len writes given data with 2 bytes of its length.
func WriteBytesWithUInt16Len(w io.Writer, data []byte) error {
l := len(data)
if l > math.MaxInt16 {
return errors.Errorf("invalid data length %d", l)
}
var size [uint16Size]byte
binary.BigEndian.PutUint16(size[:], uint16(l))
if _, err := w.Write(size[:]); err != nil {
return errors.Wrap(err, "failed to write uin16 data size")
}
if _, err := w.Write(data); err != nil {
return errors.Wrap(err, "failed to write data")
}
return nil
}

// BytesWithUInt16Len reads from buf an array of bytes of length encoded in first 2 bytes.
func BytesWithUInt16Len(buf []byte) ([]byte, error) {
if l := len(buf); l < 2 {
Expand Down
Loading

0 comments on commit 35c0265

Please sign in to comment.