fix bug where newly published and transferred videos caused an error

rename variable for better clarity
This commit is contained in:
Niko Storni 2019-10-08 01:59:18 +02:00
parent 5171acc007
commit 44e6cb5ddc
4 changed files with 73 additions and 70 deletions

View file

@ -126,24 +126,24 @@ func (s *SyncManager) Start() error {
lbryChannelName := channels[0].DesiredChannelName lbryChannelName := channels[0].DesiredChannelName
syncs = make([]Sync, 1) syncs = make([]Sync, 1)
syncs[0] = Sync{ syncs[0] = Sync{
APIConfig: s.apiConfig, APIConfig: s.apiConfig,
YoutubeChannelID: s.syncProperties.YoutubeChannelID, YoutubeChannelID: s.syncProperties.YoutubeChannelID,
LbryChannelName: lbryChannelName, LbryChannelName: lbryChannelName,
lbryChannelID: channels[0].ChannelClaimID, lbryChannelID: channels[0].ChannelClaimID,
MaxTries: s.maxTries, MaxTries: s.maxTries,
ConcurrentVideos: s.concurrentVideos, ConcurrentVideos: s.concurrentVideos,
Refill: s.refill, Refill: s.refill,
Manager: s, Manager: s,
LbrycrdString: s.lbrycrdString, LbrycrdString: s.lbrycrdString,
AwsS3ID: s.awsS3ID, AwsS3ID: s.awsS3ID,
AwsS3Secret: s.awsS3Secret, AwsS3Secret: s.awsS3Secret,
AwsS3Region: s.awsS3Region, AwsS3Region: s.awsS3Region,
AwsS3Bucket: s.awsS3Bucket, AwsS3Bucket: s.awsS3Bucket,
namer: namer.NewNamer(), namer: namer.NewNamer(),
Fee: channels[0].Fee, Fee: channels[0].Fee,
publishAddress: channels[0].PublishAddress, clientPublishAddress: channels[0].PublishAddress,
publicKey: channels[0].PublicKey, publicKey: channels[0].PublicKey,
transferState: channels[0].TransferState, transferState: channels[0].TransferState,
} }
shouldInterruptLoop = true shouldInterruptLoop = true
} else { } else {
@ -169,24 +169,24 @@ func (s *SyncManager) Start() error {
for i, c := range channels { for i, c := range channels {
log.Infof("There are %d channels in the \"%s\" queue", len(channels)-i, q) log.Infof("There are %d channels in the \"%s\" queue", len(channels)-i, q)
syncs = append(syncs, Sync{ syncs = append(syncs, Sync{
APIConfig: s.apiConfig, APIConfig: s.apiConfig,
YoutubeChannelID: c.ChannelId, YoutubeChannelID: c.ChannelId,
LbryChannelName: c.DesiredChannelName, LbryChannelName: c.DesiredChannelName,
lbryChannelID: c.ChannelClaimID, lbryChannelID: c.ChannelClaimID,
MaxTries: s.maxTries, MaxTries: s.maxTries,
ConcurrentVideos: s.concurrentVideos, ConcurrentVideos: s.concurrentVideos,
Refill: s.refill, Refill: s.refill,
Manager: s, Manager: s,
LbrycrdString: s.lbrycrdString, LbrycrdString: s.lbrycrdString,
AwsS3ID: s.awsS3ID, AwsS3ID: s.awsS3ID,
AwsS3Secret: s.awsS3Secret, AwsS3Secret: s.awsS3Secret,
AwsS3Region: s.awsS3Region, AwsS3Region: s.awsS3Region,
AwsS3Bucket: s.awsS3Bucket, AwsS3Bucket: s.awsS3Bucket,
namer: namer.NewNamer(), namer: namer.NewNamer(),
Fee: c.Fee, Fee: c.Fee,
publishAddress: c.PublishAddress, clientPublishAddress: c.PublishAddress,
publicKey: c.PublicKey, publicKey: c.PublicKey,
transferState: c.TransferState, transferState: c.TransferState,
}) })
if q != StatusFailed { if q != StatusFailed {
continue queues continue queues

View file

@ -131,7 +131,7 @@ func (s *Sync) walletSetup() error {
return errors.Err("found blank claim address") return errors.Err("found blank claim address")
} }
if s.shouldTransfer() { if s.shouldTransfer() {
s.claimAddress = s.publishAddress s.claimAddress = s.clientPublishAddress
} }
err = s.ensureEnoughUTXOs() err = s.ensureEnoughUTXOs()

View file

@ -61,7 +61,7 @@ func abandonSupports(s *Sync) (float64, error) {
if ok { if ok {
continue continue
} }
supportOnTransferredClaim := support.Address == s.publishAddress //todo: probably not needed anymore supportOnTransferredClaim := support.Address == s.clientPublishAddress //todo: probably not needed anymore
if supportOnTransferredClaim { if supportOnTransferredClaim {
continue continue
} }
@ -87,7 +87,7 @@ func transferVideos(s *Sync) error {
cleanTransfer := true cleanTransfer := true
for _, video := range s.syncedVideos { for _, video := range s.syncedVideos {
if !video.Published || video.Transferred || video.MetadataVersion != LatestMetadataVersion { if !video.Published || video.Transferred || video.MetadataVersion != LatestMetadataVersion {
log.Debugf("skipping video: %s", video.VideoID) //log.Debugf("skipping video: %s", video.VideoID)
continue continue
} }
@ -102,9 +102,12 @@ func transferVideos(s *Sync) error {
return errors.Err("cannot transfer: too many claims. claimID: %s", video.ClaimID) return errors.Err("cannot transfer: too many claims. claimID: %s", video.ClaimID)
} }
if c.Claims[0].Address == s.clientPublishAddress {
continue
}
streamUpdateOptions := jsonrpc.StreamUpdateOptions{ streamUpdateOptions := jsonrpc.StreamUpdateOptions{
StreamCreateOptions: &jsonrpc.StreamCreateOptions{ StreamCreateOptions: &jsonrpc.StreamCreateOptions{
ClaimCreateOptions: jsonrpc.ClaimCreateOptions{ClaimAddress: &s.publishAddress}, ClaimCreateOptions: jsonrpc.ClaimCreateOptions{ClaimAddress: &s.clientPublishAddress},
}, },
Bid: util.PtrToString("0.005"), // Todo - Dont hardcode Bid: util.PtrToString("0.005"), // Todo - Dont hardcode
} }
@ -152,14 +155,14 @@ func transferChannel(s *Sync) error {
if channelClaim == nil || len(channelClaim.Claims) == 0 { if channelClaim == nil || len(channelClaim.Claims) == 0 {
return errors.Err("There is no channel claim for channel %s", s.LbryChannelName) return errors.Err("There is no channel claim for channel %s", s.LbryChannelName)
} }
if channelClaim.Claims[0].Address == s.publishAddress { if channelClaim.Claims[0].Address == s.clientPublishAddress {
return nil return nil
} }
updateOptions := jsonrpc.ChannelUpdateOptions{ updateOptions := jsonrpc.ChannelUpdateOptions{
Bid: util.PtrToString(fmt.Sprintf("%.6f", channelClaimAmount-0.005)), Bid: util.PtrToString(fmt.Sprintf("%.6f", channelClaimAmount-0.005)),
ChannelCreateOptions: jsonrpc.ChannelCreateOptions{ ChannelCreateOptions: jsonrpc.ChannelCreateOptions{
ClaimCreateOptions: jsonrpc.ClaimCreateOptions{ ClaimCreateOptions: jsonrpc.ClaimCreateOptions{
ClaimAddress: &s.publishAddress, ClaimAddress: &s.clientPublishAddress,
}, },
}, },
} }

View file

@ -63,32 +63,32 @@ func (a byPublishedAt) Less(i, j int) bool { return a[i].PublishedAt().Before(a[
// Sync stores the options that control how syncing happens // Sync stores the options that control how syncing happens
type Sync struct { type Sync struct {
APIConfig *sdk.APIConfig APIConfig *sdk.APIConfig
YoutubeChannelID string YoutubeChannelID string
LbryChannelName string LbryChannelName string
MaxTries int MaxTries int
ConcurrentVideos int ConcurrentVideos int
Refill int Refill int
Manager *SyncManager Manager *SyncManager
LbrycrdString string LbrycrdString string
AwsS3ID string AwsS3ID string
AwsS3Secret string AwsS3Secret string
AwsS3Region string AwsS3Region string
AwsS3Bucket string AwsS3Bucket string
Fee *sdk.Fee Fee *sdk.Fee
daemon *jsonrpc.Client daemon *jsonrpc.Client
claimAddress string claimAddress string
videoDirectory string videoDirectory string
syncedVideosMux *sync.RWMutex syncedVideosMux *sync.RWMutex
syncedVideos map[string]sdk.SyncedVideo syncedVideos map[string]sdk.SyncedVideo
grp *stop.Group grp *stop.Group
lbryChannelID string lbryChannelID string
namer *namer.Namer namer *namer.Namer
walletMux *sync.RWMutex walletMux *sync.RWMutex
queue chan video queue chan video
transferState int transferState int
publishAddress string clientPublishAddress string
publicKey string publicKey string
} }
func (s *Sync) AppendSyncedVideo(videoID string, published bool, failureReason string, claimName string, claimID string, metadataVersion int8, size int64) { func (s *Sync) AppendSyncedVideo(videoID string, published bool, failureReason string, claimName string, claimID string, metadataVersion int8, size int64) {
@ -373,7 +373,7 @@ func deleteSyncFolder(videoDirectory string) {
} }
func (s *Sync) shouldTransfer() bool { func (s *Sync) shouldTransfer() bool {
return s.transferState >= 1 && s.publishAddress != "" && !s.Manager.SyncFlags.DisableTransfers return s.transferState >= 1 && s.clientPublishAddress != "" && !s.Manager.SyncFlags.DisableTransfers
} }
func (s *Sync) setChannelTerminationStatus(e *error) { func (s *Sync) setChannelTerminationStatus(e *error) {
@ -505,7 +505,7 @@ func (s *Sync) fixDupes(claims []jsonrpc.Claim) (bool, error) {
claimToAbandon = cl claimToAbandon = cl
videoIDs[videoID] = c videoIDs[videoID] = c
} }
if claimToAbandon.Address != s.publishAddress && !s.syncedVideos[videoID].Transferred { if claimToAbandon.Address != s.clientPublishAddress && !s.syncedVideos[videoID].Transferred {
log.Debugf("abandoning %+v", claimToAbandon) log.Debugf("abandoning %+v", claimToAbandon)
_, err := s.daemon.StreamAbandon(claimToAbandon.Txid, claimToAbandon.Nout, nil, false) _, err := s.daemon.StreamAbandon(claimToAbandon.Txid, claimToAbandon.Nout, nil, false)
if err != nil { if err != nil {