Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log record about rollback action. #1466

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions pkg/grpc/server/accounts_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ func (s *Server) GetBalances(req *g.BalancesRequest, srv g.AccountsApi_GetBalanc
c := proto.ProtobufConverter{FallbackChainID: s.scheme}
addr, err := c.Address(s.scheme, req.Address)
if err != nil {
return status.Errorf(codes.InvalidArgument, err.Error())
return status.Error(codes.InvalidArgument, err.Error())
}
rcp := proto.NewRecipientFromAddress(addr)
if len(req.Assets) == 0 {
// TODO(nickeskov): send waves balance AND all assets balances (portfolio)
// by the given address according to the scala node implementation
if err := s.sendWavesBalance(rcp, srv); err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
}
for _, asset := range req.Assets {
if len(asset) == 0 {
if err := s.sendWavesBalance(rcp, srv); err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
} else {
// Asset.
fullAssetID, err := crypto.NewDigestFromBytes(asset)
if err != nil {
return status.Errorf(codes.InvalidArgument, err.Error())
return status.Error(codes.InvalidArgument, err.Error())
}
balance, err := s.state.AssetBalance(rcp, proto.AssetIDFromDigest(fullAssetID))
if err != nil {
return status.Errorf(codes.NotFound, err.Error())
return status.Error(codes.NotFound, err.Error())
}
var res g.BalanceResponse
res.Balance = &g.BalanceResponse_Asset{
Expand All @@ -51,7 +51,7 @@ func (s *Server) GetBalances(req *g.BalancesRequest, srv g.AccountsApi_GetBalanc
},
}
if err := srv.Send(&res); err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
}
}
Expand All @@ -62,7 +62,7 @@ func (s *Server) GetScript(_ context.Context, req *g.AccountRequest) (*g.ScriptR
c := proto.ProtobufConverter{FallbackChainID: s.scheme}
addr, err := c.Address(s.scheme, req.Address)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
return nil, status.Error(codes.InvalidArgument, err.Error())
}
rcp := proto.NewRecipientFromAddress(addr)
scriptInfo, err := s.state.ScriptInfoByAccount(rcp)
Expand All @@ -75,15 +75,15 @@ func (s *Server) GetScript(_ context.Context, req *g.AccountRequest) (*g.ScriptR
func (s *Server) GetActiveLeases(req *g.AccountRequest, srv g.AccountsApi_GetActiveLeasesServer) error {
extendedApi, err := s.state.ProvidesExtendedApi()
if err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
if !extendedApi {
return status.Errorf(codes.FailedPrecondition, "Node's state does not have information required for extended API")
return status.Error(codes.FailedPrecondition, "Node's state does not have information required for extended API")
}
c := proto.ProtobufConverter{FallbackChainID: s.scheme}
addr, err := c.Address(s.scheme, req.Address)
if err != nil {
return status.Errorf(codes.InvalidArgument, err.Error())
return status.Error(codes.InvalidArgument, err.Error())
}

filterFn := func(tx proto.Transaction) bool {
Expand All @@ -100,15 +100,15 @@ func (s *Server) GetActiveLeases(req *g.AccountRequest, srv g.AccountsApi_GetAct
}
iter, err := s.state.NewAddrTransactionsIterator(addr)
if err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
if iter == nil {
// Nothing to iterate.
return nil
}
handler := &getActiveLeasesHandler{srv, s}
if err := s.iterateAndHandleTransactions(iter, filterFn, handler.handle); err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
return nil
}
Expand All @@ -117,40 +117,40 @@ func (s *Server) GetDataEntries(req *g.DataRequest, srv g.AccountsApi_GetDataEnt
c := proto.ProtobufConverter{FallbackChainID: s.scheme}
addr, err := c.Address(s.scheme, req.Address)
if err != nil {
return status.Errorf(codes.InvalidArgument, err.Error())
return status.Error(codes.InvalidArgument, err.Error())
}
rcp := proto.NewRecipientFromAddress(addr)
if req.Key != "" {
entry, err := s.state.RetrieveEntry(rcp, req.Key)
if err != nil {
if err.Error() == "not found" {
if err.Error() == "not found" { // TODO: fix this error message comparison, use errors.Is instead
return nil
}
return status.Errorf(codes.NotFound, err.Error())
return status.Error(codes.NotFound, err.Error())
}
if entry.GetValueType() == proto.DataDelete { // Send "Not Found" if entry was removed
return status.Errorf(codes.NotFound, "entry removed")
return status.Error(codes.NotFound, "entry removed")
}
res := &g.DataEntryResponse{Address: req.Address, Entry: entry.ToProtobuf()}
if err := srv.Send(res); err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
return nil
}
entries, err := s.state.RetrieveEntries(rcp)
if err != nil {
if err.Error() == "not found" {
if err.Error() == "not found" { // TODO: fix this error message comparison, use errors.Is instead
return nil
}
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
for _, entry := range entries {
if entry.GetValueType() == proto.DataDelete {
continue // Do not send removed entries
}
res := &g.DataEntryResponse{Address: req.Address, Entry: entry.ToProtobuf()}
if err := srv.Send(res); err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
}
return nil
Expand All @@ -160,7 +160,7 @@ func (s *Server) ResolveAlias(_ context.Context, req *wrapperspb.StringValue) (*
alias := proto.NewAlias(s.scheme, req.Value)
addr, err := s.state.AddrByAlias(*alias)
if err != nil {
return nil, status.Errorf(codes.NotFound, err.Error())
return nil, status.Error(codes.NotFound, err.Error())
}
return &wrapperspb.BytesValue{Value: addr.Bytes()}, nil
}
Expand Down
21 changes: 11 additions & 10 deletions pkg/grpc/server/assets_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ package server
import (
"context"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/wavesplatform/gowaves/pkg/crypto"
g "github.com/wavesplatform/gowaves/pkg/grpc/generated/waves/node/grpc"
"github.com/wavesplatform/gowaves/pkg/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (s *Server) GetInfo(_ context.Context, req *g.AssetRequest) (*g.AssetInfoResponse, error) {
// we expect full asset id (crypto.Digest)
fullAssetID, err := crypto.NewDigestFromBytes(req.AssetId)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
return nil, status.Error(codes.InvalidArgument, err.Error())
}
ai, err := s.state.FullAssetInfo(proto.AssetIDFromDigest(fullAssetID))
if err != nil {
return nil, status.Errorf(codes.NotFound, err.Error())
return nil, status.Error(codes.NotFound, err.Error())
}
res, err := ai.ToProtobuf(s.scheme)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
return res, nil
}
Expand All @@ -31,30 +32,30 @@ func (s *Server) GetNFTList(req *g.NFTRequest, srv g.AssetsApi_GetNFTListServer)
c := proto.ProtobufConverter{FallbackChainID: s.scheme}
addr, err := c.Address(s.scheme, req.Address)
if err != nil {
return status.Errorf(codes.InvalidArgument, err.Error())
return status.Error(codes.InvalidArgument, err.Error())
}
var afterAssetID *proto.AssetID
if len(req.AfterAssetId) != 0 {
// we expect full asset id (crypto.Digest)
fullAssetID, err := crypto.NewDigestFromBytes(req.AfterAssetId)
if err != nil {
return status.Errorf(codes.InvalidArgument, err.Error())
return status.Error(codes.InvalidArgument, err.Error())
}
assetID := proto.AssetIDFromDigest(fullAssetID)
afterAssetID = &assetID
}
nfts, err := s.state.NFTList(proto.NewRecipientFromAddress(addr), uint64(req.Limit), afterAssetID)
if err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
for _, nft := range nfts {
ai, err := nft.ToProtobuf(s.scheme)
if err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
res := &g.NFTResponse{AssetId: nft.ID.Bytes(), AssetInfo: ai}
if err := srv.Send(res); err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
}
return nil
Expand Down
23 changes: 12 additions & 11 deletions pkg/grpc/server/blockchain_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package server
import (
"context"

g "github.com/wavesplatform/gowaves/pkg/grpc/generated/waves/node/grpc"
"github.com/wavesplatform/gowaves/pkg/settings"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"

g "github.com/wavesplatform/gowaves/pkg/grpc/generated/waves/node/grpc"
"github.com/wavesplatform/gowaves/pkg/settings"
)

// allFeatures combines blockchain features from state with features
Expand Down Expand Up @@ -80,30 +81,30 @@ func (s *Server) featureActivationStatus(id int16, height uint64) (*g.FeatureAct
func (s *Server) GetActivationStatus(ctx context.Context, req *g.ActivationStatusRequest) (*g.ActivationStatusResponse, error) {
height, err := s.state.Height()
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
if req.Height > int32(height) {
return nil, status.Errorf(codes.FailedPrecondition, "requested height exceeds current height")
return nil, status.Error(codes.FailedPrecondition, "requested height exceeds current height")
}
reqHeight := uint64(req.Height)
res := &g.ActivationStatusResponse{Height: req.Height}
sets, err := s.state.BlockchainSettings()
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
res.VotingInterval = int32(sets.ActivationWindowSize(reqHeight))
res.VotingThreshold = int32(sets.VotesForFeatureElection(reqHeight))
prevCheck := reqHeight - (reqHeight % uint64(res.VotingInterval))
res.NextCheck = int32(prevCheck) + res.VotingInterval
features, err := s.allFeatures()
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
res.Features = make([]*g.FeatureActivationStatus, len(features))
for i, id := range features {
res.Features[i], err = s.featureActivationStatus(id, reqHeight)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
}
return res, nil
Expand All @@ -112,23 +113,23 @@ func (s *Server) GetActivationStatus(ctx context.Context, req *g.ActivationStatu
func (s *Server) GetBaseTarget(ctx context.Context, req *emptypb.Empty) (*g.BaseTargetResponse, error) {
height, err := s.state.Height()
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
block, err := s.state.BlockByHeight(height)
if err != nil {
return nil, status.Errorf(codes.NotFound, err.Error())
return nil, status.Error(codes.NotFound, err.Error())
}
return &g.BaseTargetResponse{BaseTarget: int64(block.BaseTarget)}, nil
}

func (s *Server) GetCumulativeScore(ctx context.Context, req *emptypb.Empty) (*g.ScoreResponse, error) {
score, err := s.state.CurrentScore()
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
scoreBytes, err := score.GobEncode()
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
return &g.ScoreResponse{Score: scoreBytes}, nil
}
26 changes: 13 additions & 13 deletions pkg/grpc/server/blocks_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ import (
func (s *Server) headerByHeight(height proto.Height) (*g.BlockWithHeight, error) {
header, err := s.state.HeaderByHeight(height)
if err != nil {
return nil, status.Errorf(codes.NotFound, err.Error())
return nil, status.Error(codes.NotFound, err.Error())
}
vrf, rewards, err := calculateVRFAndRewards(s.state, s.scheme, header, height)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
res, err := header.HeaderToProtobufWithHeight(s.scheme, height, vrf, rewards)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
return res, nil
}

func (s *Server) blockByHeight(height proto.Height) (*g.BlockWithHeight, error) {
block, err := s.state.BlockByHeight(height)
if err != nil {
return nil, status.Errorf(codes.NotFound, err.Error())
return nil, status.Error(codes.NotFound, err.Error())
}
vrf, rewards, err := calculateVRFAndRewards(s.state, s.scheme, &block.BlockHeader, height)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
res, err := block.ToProtobufWithHeight(s.scheme, height, vrf, rewards)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
return res, nil
}
Expand Down Expand Up @@ -86,17 +86,17 @@ func (s *Server) GetBlock(ctx context.Context, req *g.BlockRequest) (*g.BlockWit
case *g.BlockRequest_BlockId:
id, err := proto.NewBlockIDFromBytes(r.BlockId)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
return nil, status.Error(codes.InvalidArgument, err.Error())
}
blockHeight, err := s.state.BlockIDToHeight(id)
if err != nil {
return nil, status.Errorf(codes.NotFound, err.Error())
return nil, status.Error(codes.NotFound, err.Error())
}
return s.headerOrBlockByHeight(blockHeight, req.IncludeTransactions)
case *g.BlockRequest_Height:
return s.headerOrBlockByHeight(proto.Height(r.Height), req.IncludeTransactions)
default:
return nil, status.Errorf(codes.InvalidArgument, "Unknown argument type")
return nil, status.Error(codes.InvalidArgument, "Unknown argument type")
}
}

Expand All @@ -123,21 +123,21 @@ func (s *Server) GetBlockRange(req *g.BlockRangeRequest, srv g.BlocksApi_GetBloc
}
stateHeight, err := s.state.Height()
if err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
if req.ToHeight > uint32(stateHeight) {
req.ToHeight = uint32(stateHeight)
}
for height := proto.Height(req.FromHeight); height <= proto.Height(req.ToHeight); height++ {
block, err := s.headerOrBlockByHeight(height, req.IncludeTransactions)
if err != nil {
return status.Errorf(codes.NotFound, err.Error())
return status.Error(codes.NotFound, err.Error())
}
if !filter(block) {
continue
}
if err := srv.Send(block); err != nil {
return status.Errorf(codes.Internal, err.Error())
return status.Error(codes.Internal, err.Error())
}
}
return nil
Expand All @@ -146,7 +146,7 @@ func (s *Server) GetBlockRange(req *g.BlockRangeRequest, srv g.BlocksApi_GetBloc
func (s *Server) GetCurrentHeight(ctx context.Context, req *emptypb.Empty) (*wrapperspb.UInt32Value, error) {
height, err := s.state.Height()
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
return &wrapperspb.UInt32Value{Value: uint32(height)}, nil
}
Loading
Loading