Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(engine)!: determinism bug with log entries #926

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions dan_layer/engine_types/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{
fmt::Display,
time::{Duration, SystemTime, UNIX_EPOCH},
};
use std::fmt::Display;

use serde::{Deserialize, Serialize};
pub use tari_template_lib::args::LogLevel;
Expand All @@ -33,29 +30,18 @@ use ts_rs::TS;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))]
pub struct LogEntry {
#[cfg_attr(feature = "ts", ts(type = "number"))]
pub timestamp: u64,
pub message: String,
pub level: LogLevel,
}

impl LogEntry {
pub fn new(level: LogLevel, message: String) -> Self {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
// If the errors, the clock has been set before the UNIX_EPOCH
.unwrap_or_else(|_| Duration::from_secs(0))
.as_secs();
Self {
timestamp: now,
message,
level,
}
Self { message, level }
}
}

impl Display for LogEntry {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} {} {}", self.timestamp, self.level, self.message)
write!(f, "{} {}", self.level, self.message)
}
}
Loading