github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/cmd/geth/log_display_util.go (about) 1 package main 2 3 import ( 4 "time" 5 6 "github.com/ethereumproject/go-ethereum/eth" 7 "github.com/ethereumproject/go-ethereum/eth/downloader" 8 "gopkg.in/urfave/cli.v1" 9 ) 10 11 //go:generate stringer -type=logEventType 12 type logEventType int 13 14 const ( 15 logEventCoreChainInsert logEventType = iota 16 logEventCoreChainInsertSide 17 logEventCoreHeaderChainInsert 18 logEventCoreReceiptChainInsert 19 logEventCoreMinedBlock 20 logEventDownloaderStart 21 logEventDownloaderDone 22 logEventDownloaderFailed 23 logEventDownloaderInsertChain 24 logEventDownloaderInsertReceiptChain 25 logEventDownloaderInsertHeaderChain 26 logEventFetcherInsert 27 logEventPMHandlerAdd 28 logEventPMHandlerRemove 29 logEventInterval 30 logEventBefore 31 logEventAfter 32 ) 33 34 // Global bookmark vars. 35 // These are accessible globally to allow inter-communication between display system event handlers. 36 // Note: since these may be read/modified from concurrent operations (eg. handler fns), these variables are NOT thread safe. 37 // In the case that a logging operation requires thread safety, use externally implemented locking. 38 var currentMode = lsModeDiscover 39 var currentBlockNumber uint64 40 var chainEventLastSent time.Time 41 42 // updateLogStatusModeHandler implements the displayEventHandlerFn signature interface 43 // It is a convenience fn to update the global 'currentMode' var. 44 // Typically it should be called from downloader events, and uses the 'getLogStatusMode' logic. 45 func updateLogStatusModeHandler(ctx *cli.Context, e *eth.Ethereum, evData interface{}, tickerInterval time.Duration) { 46 currentMode = getLogStatusMode(e) 47 } 48 49 // getLogStatusMode gets the "mode" for the ethereum node at any given time. 50 // It is used to set the global bookmark variable, and influences formatting logic. 51 func getLogStatusMode(e *eth.Ethereum) lsMode { 52 if e.Downloader().Synchronising() { 53 switch e.Downloader().GetMode() { 54 case downloader.FullSync: 55 return lsModeFullSync 56 case downloader.FastSync: 57 return lsModeFastSync 58 } 59 } 60 if e.Downloader().GetPeers().Len() == 0 { 61 return lsModeDiscover 62 } 63 _, current, height, _, _ := e.Downloader().Progress() // origin, current, height, pulled, known 64 if height > 0 && height < current { 65 return lsModeImport 66 } 67 return lsModeDiscover 68 }