Skip to content

Commit

Permalink
Add debug records.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickeskov committed Aug 24, 2024
1 parent fe06272 commit e7a52ec
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
18 changes: 17 additions & 1 deletion pkg/ride/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/ride/functions_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 13 additions & 4 deletions pkg/state/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
32 changes: 26 additions & 6 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,15 +981,25 @@ 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) {
addr, err := s.NewestRecipientToAddress(account)
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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit e7a52ec

Please sign in to comment.