adjust support management

adjust e2e script
This commit is contained in:
Niko Storni 2019-08-28 21:08:25 +02:00
parent 7b23235f83
commit 3c3ea2138e
4 changed files with 42 additions and 14 deletions

View file

@ -84,7 +84,7 @@ services:
## Internal APIs ## ## Internal APIs ##
################### ###################
internalapis: internalapis:
image: lbry/internal-apis:transfers image: lbry/internal-apis:master
restart: "no" restart: "no"
ports: ports:
- "15400:8080" - "15400:8080"

View file

@ -70,11 +70,11 @@ mysql -u lbry -plbry -ss -D lbry -h "127.0.0.1" -P 15500 -e "UPDATE youtube_data
curl -i -H 'Accept: application/json' -H 'Content-Type: application/json' 'http://localhost:15400/yt/transfer?auth_token=youtubertoken&address=n1Ygra2pyD6cpESv9GtPM9kDkr4bPeu1Dc' curl -i -H 'Accept: application/json' -H 'Content-Type: application/json' 'http://localhost:15400/yt/transfer?auth_token=youtubertoken&address=n1Ygra2pyD6cpESv9GtPM9kDkr4bPeu1Dc'
# Execute the transfer test! # Execute the transfer test!
./../bin/ytsync --channelID UCCyr5j8akeu9j4Q7urV0Lqw #Force channel intended...just in case. This channel lines up with the api container ./../bin/ytsync --channelID UCCyr5j8akeu9j4Q7urV0Lqw #Force channel intended...just in case. This channel lines up with the api container
# ALSO CHECK THAT VIDEO IS MARKED TRANSFERRED # Check that the channel and the video are marked as transferred and that all supports are spent
channelTransferStatus=$(mysql -u lbry -plbry -ss -D lbry -h "127.0.0.1" -P 15500 -e 'SELECT transfer_state FROM youtube_data WHERE id=1') channelTransferStatus=$(mysql -u lbry -plbry -ss -D lbry -h "127.0.0.1" -P 15500 -e 'SELECT transfer_state FROM youtube_data WHERE id=1')
videoTransferStatus=$(mysql -u lbry -plbry -ss -D lbry -h "127.0.0.1" -P 15500 -e 'SELECT transferred FROM synced_video WHERE id=1') videoTransferStatus=$(mysql -u lbry -plbry -ss -D lbry -h "127.0.0.1" -P 15500 -e 'SELECT transferred FROM synced_video WHERE id=1')
nrUnspentSupports=$(mysql -u lbry -plbry -ss -D chainquery -h "127.0.0.1" -P 15600 -e 'SELECT COUNT(*) FROM chainquery.support INNER JOIN output ON output.transaction_hash = support.transaction_hash_id AND output.vout = support.vout WHERE output.is_spent = 0') nrUnspentSupports=$(mysql -u lbry -plbry -ss -D chainquery -h "127.0.0.1" -P 15600 -e 'SELECT COUNT(*) FROM chainquery.support INNER JOIN output ON output.transaction_hash = support.transaction_hash_id AND output.vout = support.vout WHERE output.is_spent = 0')
if [[ $status != "synced" || $videoStatus != "published" || $channelTransferStatus != "2" || $videoTransferStatus != "1" || $nrUnspentSupports != "0" ]]; then if [[ $status != "synced" || $videoStatus != "published" || $channelTransferStatus != "2" || $videoTransferStatus != "1" || $nrUnspentSupports != "1" ]]; then
echo "~~!!!~~~FAILED~~~!!!~~" echo "~~!!!~~~FAILED~~~!!!~~"
echo "Channel Status: $status" echo "Channel Status: $status"
echo "Video Status: $videoStatus" echo "Video Status: $videoStatus"
@ -88,6 +88,4 @@ if [[ $status != "synced" || $videoStatus != "published" || $channelTransferStat
exit 1; exit 1;
else else
echo "SUCCESSSSSSSSSSSSS!" echo "SUCCESSSSSSSSSSSSS!"
fi; fi;
#perhaps query lbrynet again (should be restarted) to see if the claim and the channel are actually on the right address

View file

@ -6,6 +6,7 @@ import (
"github.com/lbryio/lbry.go/extras/util" "github.com/lbryio/lbry.go/extras/util"
"github.com/lbryio/ytsync/sdk" "github.com/lbryio/ytsync/sdk"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"strconv"
) )
func waitConfirmations(s *Sync) error { func waitConfirmations(s *Sync) error {
@ -33,18 +34,19 @@ waiting:
return nil return nil
} }
func abandonSupports(s *Sync) error { func abandonSupports(s *Sync) (float64, error) {
totalPages := uint64(1) totalPages := uint64(1)
var allSupports []jsonrpc.Claim var allSupports []jsonrpc.Claim
for page := uint64(1); page <= totalPages; page++ { for page := uint64(1); page <= totalPages; page++ {
supports, err := s.daemon.SupportList(nil, page, 50) supports, err := s.daemon.SupportList(nil, page, 50)
if err != nil { if err != nil {
return errors.Prefix("cannot list claims", err) return 0, errors.Prefix("cannot list claims", err)
} }
allSupports = append(allSupports, (*supports).Items...) allSupports = append(allSupports, (*supports).Items...)
totalPages = (*supports).TotalPages totalPages = (*supports).TotalPages
} }
alreadyAbandoned := make(map[string]bool, len(allSupports)) alreadyAbandoned := make(map[string]bool, len(allSupports))
totalAbandoned := 0.0
for _, support := range allSupports { for _, support := range allSupports {
_, ok := alreadyAbandoned[support.ClaimID] _, ok := alreadyAbandoned[support.ClaimID]
if ok { if ok {
@ -53,11 +55,19 @@ func abandonSupports(s *Sync) error {
alreadyAbandoned[support.ClaimID] = true alreadyAbandoned[support.ClaimID] = true
summary, err := s.daemon.SupportAbandon(&support.ClaimID, nil, nil, nil, nil) summary, err := s.daemon.SupportAbandon(&support.ClaimID, nil, nil, nil, nil)
if err != nil { if err != nil {
return errors.Err(err) return totalAbandoned, errors.Err(err)
} }
log.Infof("Abandoned support of %s (%s total output) LBC for claim %s", support.Amount, summary.Outputs[0].Amount, support.ClaimID) if len(summary.Outputs) < 1 {
return totalAbandoned, errors.Err("error abandoning supports: no outputs while abandoning %s", support.ClaimID)
}
outputAmount, err := strconv.ParseFloat(summary.Outputs[0].Amount, 64)
if err != nil {
return totalAbandoned, errors.Err(err)
}
totalAbandoned += outputAmount
log.Infof("Abandoned supports of %.4f LBC for claim %s", outputAmount, support.ClaimID)
} }
return nil return totalAbandoned, nil
} }
func transferVideos(s *Sync) error { func transferVideos(s *Sync) error {

View file

@ -320,15 +320,35 @@ func (s *Sync) FullCycle() (e error) {
if err != nil { if err != nil {
return err return err
} }
err = abandonSupports(s) supportAmount, err := abandonSupports(s)
if err != nil { if err != nil {
return err return errors.Prefix(fmt.Sprintf("%.6f LBCs were abandoned before failing", supportAmount), err)
} }
err = transferVideos(s) err = transferVideos(s)
if err != nil { if err != nil {
return err return err
} }
return transferChannel(s) err = transferChannel(s)
if err != nil {
return err
}
reallocateSupports := supportAmount > 0.01
if reallocateSupports {
err = waitConfirmations(s)
if err != nil {
return err
}
isTip := true
summary, err := s.daemon.SupportCreate(s.lbryChannelID, fmt.Sprintf("%.6f", supportAmount), &isTip, nil, nil)
if err != nil {
return errors.Err(err)
}
if len(summary.Outputs) < 1 {
return errors.Err("something went wrong while tipping the channel for %.6f LBCs", supportAmount)
}
}
return nil
} }
return nil return nil