From e7a52ecf2466c6c0ab690e2331e44d5147ae0fa6 Mon Sep 17 00:00:00 2001 From: Nikolay Eskov Date: Wed, 21 Aug 2024 18:31:01 +0300 Subject: [PATCH] Add debug records. --- pkg/ride/environment.go | 18 +++++++++++++++++- pkg/ride/functions_proto.go | 2 ++ pkg/state/balances.go | 17 +++++++++++++---- pkg/state/state.go | 32 ++++++++++++++++++++++++++------ 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/pkg/ride/environment.go b/pkg/ride/environment.go index 066c2468e4..6dbd7c072e 100644 --- a/pkg/ride/environment.go +++ b/pkg/ride/environment.go @@ -5,6 +5,7 @@ import ( "math" "github.com/pkg/errors" + "go.uber.org/zap" "github.com/wavesplatform/gowaves/pkg/crypto" "github.com/wavesplatform/gowaves/pkg/errs" @@ -153,7 +154,22 @@ func (ws *WrappedState) NewestFullWavesBalance(account proto.Recipient) (*proto. if err != nil { return nil, err } - return b.toFullWavesBalance() + zap.S().Infof("WrappedState.NewestFullWavesBalance: addr=%s, %+v", fmt.Stringer(addr), struct { + Balance, LeaseIn, LeaseOut, StateGenerating int64 + Challenged bool + }{ + Balance: b.balance, LeaseIn: b.leaseIn, LeaseOut: b.leaseOut, StateGenerating: b.stateGenerating, + Challenged: b.challenged, + }) + fullWavesBalance, err := b.toFullWavesBalance() + if err != nil { + return nil, err + } + zap.S().Infof("WrappedState.NewestFullWavesBalance.toFullWavesBalance: addr=%s, %+v", + fmt.Stringer(addr), + fullWavesBalance, + ) + return fullWavesBalance, nil } func (ws *WrappedState) IsStateUntouched(account proto.Recipient) (bool, error) { diff --git a/pkg/ride/functions_proto.go b/pkg/ride/functions_proto.go index 46a49642ea..ba73beda7c 100644 --- a/pkg/ride/functions_proto.go +++ b/pkg/ride/functions_proto.go @@ -11,6 +11,7 @@ import ( "github.com/consensys/gnark-crypto/ecc" "github.com/mr-tron/base58" "github.com/pkg/errors" + "go.uber.org/zap" "golang.org/x/crypto/blake2b" "github.com/wavesplatform/gowaves/pkg/consensus" @@ -825,6 +826,7 @@ func wavesBalanceV4(env environment, args ...rideType) (rideType, error) { if err != nil { return nil, errors.Wrapf(err, "wavesBalanceV4(%s)", r.String()) } + zap.S().Infof("wavesBalanceV4(%s) = %+v", r.String(), balance) return balanceDetailsToObject(balance), nil } diff --git a/pkg/state/balances.go b/pkg/state/balances.go index 52edf83c66..0defc25802 100644 --- a/pkg/state/balances.go +++ b/pkg/state/balances.go @@ -649,7 +649,7 @@ func (s *balances) newestGeneratingBalance(addr proto.AddressID, height proto.He } func (s *balances) storeChallenge( - challenger, challenged proto.AddressID, + challenger, challenged proto.Address, blockchainHeight proto.Height, // for changing generating balance we use current blockchain height blockID proto.BlockID, ) error { @@ -659,16 +659,25 @@ func (s *balances) storeChallenge( } // Get challenger bonus before storing the challenged penalty. // Challenged can't be with bonus and be challenged at the same height because of the check above. - generatingBalance, gbErr := s.newestGeneratingBalance(challenged, blockchainHeight) + generatingBalance, gbErr := s.newestGeneratingBalance(challenged.ID(), blockchainHeight) if gbErr != nil { return errors.Wrapf(gbErr, "failed to get generating balance for challenged address at height %d", blockchainHeight) } - if err := s.storeChallengeBonusForAddr(challenger, generatingBalance, blockchainHeight, blockID); err != nil { + challengerGeneratingBalance, cgbErr := s.newestGeneratingBalance(challenger.ID(), blockchainHeight) + if cgbErr != nil { + return errors.Wrapf(cgbErr, "failed to get generating balance for challenger address at height %d", blockchainHeight) + } + zap.S().Infof("Storing challenge bonus for challenger %s with original balance %d at height %d: %d + %d = %d", + challenger.String(), challengerGeneratingBalance, blockchainHeight, + challengerGeneratingBalance, generatingBalance, challengerGeneratingBalance+generatingBalance, + ) + if err := s.storeChallengeBonusForAddr(challenger.ID(), generatingBalance, blockchainHeight, blockID); err != nil { return errors.Wrapf(err, "failed to store challenge bonus for challenger at height %d", blockchainHeight) } - if err := s.storeChallengeHeightForAddr(challenged, blockchainHeight, blockID); err != nil { + if err := s.storeChallengeHeightForAddr(challenged.ID(), blockchainHeight, blockID); err != nil { return errors.Wrapf(err, "failed to store challenge height for challenged at height %d", blockchainHeight) } + zap.S().Infof("Storing challenge height for challenged %s at height %d", challenged.String(), blockchainHeight) return nil } diff --git a/pkg/state/state.go b/pkg/state/state.go index 94ce09047d..1053296a1b 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -981,7 +981,12 @@ func (s *stateManager) GeneratingBalance(account proto.Recipient, height proto.H if err != nil { return 0, errs.Extend(err, "failed convert recipient to address") } - return s.stor.balances.generatingBalance(addr.ID(), height) + res, err := s.stor.balances.generatingBalance(addr.ID(), height) + if err != nil { + return 0, errs.Extend(err, "failed to get generating balance") + } + zap.S().Infof("stateManager.GeneratingBalance: addr %s, generatingBalance %d", addr.String(), res) + return res, nil } func (s *stateManager) NewestGeneratingBalance(account proto.Recipient, height proto.Height) (uint64, error) { @@ -989,7 +994,12 @@ func (s *stateManager) NewestGeneratingBalance(account proto.Recipient, height p if err != nil { return 0, wrapErr(RetrievalError, err) } - return s.stor.balances.newestGeneratingBalance(addr.ID(), height) + res, err := s.stor.balances.newestGeneratingBalance(addr.ID(), height) + if err != nil { + return 0, wrapErr(RetrievalError, err) + } + zap.S().Infof("stateManager.NewestGeneratingBalance: addr %s, generatingBalance %d", addr.String(), res) + return res, nil } func (s *stateManager) FullWavesBalance(account proto.Recipient) (*proto.FullWavesBalance, error) { @@ -1047,7 +1057,12 @@ func (s *stateManager) NewestFullWavesBalance(account proto.Recipient) (*proto.F if err != nil { return nil, wrapErr(RetrievalError, err) } - return bp.ToFullWavesBalance() + res, err := bp.ToFullWavesBalance() + if err != nil { + return nil, wrapErr(Other, err) + } + zap.S().Infof("stateManager.NewestFullWavesBalance: %+v", res) + return res, nil } // WavesBalanceProfile returns WavesBalanceProfile structure retrieved by proto.AddressID of an account. @@ -1082,13 +1097,15 @@ func (s *stateManager) WavesBalanceProfile(id proto.AddressID) (*types.WavesBala } challenged = ch } - return &types.WavesBalanceProfile{ + res := &types.WavesBalanceProfile{ Balance: profile.balance, LeaseIn: profile.leaseIn, LeaseOut: profile.leaseOut, Generating: generating, Challenged: challenged, - }, nil + } + zap.S().Infof("stateManager.WavesBalanceProfile: %+v", res) + return res, nil } func (s *stateManager) NewestWavesBalance(account proto.Recipient) (uint64, error) { @@ -1272,8 +1289,11 @@ func (s *stateManager) handleChallengedHeaderIfExists(block *proto.Block, blockH challengedHeader.GeneratorPublicKey.String(), ) } + zap.S().Infof("Challenged header found in block '%s' with challenger '%s' and challenged '%s'", + blockID.String(), challenger.String(), challenged.String(), + ) blockchainHeight := blockHeight - 1 - if chErr := s.stor.balances.storeChallenge(challenger.ID(), challenged.ID(), blockchainHeight, blockID); chErr != nil { + if chErr := s.stor.balances.storeChallenge(challenger, challenged, blockchainHeight, blockID); chErr != nil { return errors.Wrapf(chErr, "failed to store challenge with blockchain height %d for block '%s'with challenger '%s' and challenged '%s'", blockchainHeight, blockID.String(), challenger.String(), challenged.String(),